================
@@ -353,6 +367,19 @@ void SizeofExpressionCheck::check(const 
MatchFinder::MatchResult &Result) {
     diag(E->getBeginLoc(),
          "suspicious usage of 'sizeof(char*)'; do you mean 'strlen'?")
         << E->getSourceRange();
+  } else if (const auto *E = Result.Nodes.getNodeAs<Stmt>("loop-expr")) {
+    auto *SizeofArgTy = Result.Nodes.getNodeAs<Type>("sizeof-arg-type");
+    if (const auto member = dyn_cast<MemberPointerType>(SizeofArgTy)) {
+      SizeofArgTy = member->getPointeeType().getTypePtr();
+    }
+
+    if (const auto type = dyn_cast<ArrayType>(SizeofArgTy)) {
+      CharUnits sSize = Ctx.getTypeSizeInChars(type->getElementType());
+      if (!sSize.isOne()) {
+        diag(E->getBeginLoc(), "suspicious usage of 'sizeof' in the loop")
+            << E->getSourceRange();
----------------
vbvictor wrote:

Do we need this line? I think this argument is never printed because we don't 
have `%0` is message

https://github.com/llvm/llvm-project/pull/143205
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to