[clang-tools-extra] 0e55fef - [clang-tidy] Tweak diag ranges for bugprone-sizeof-expression

Piotr Zegar via cfe-commits cfe-commits at lists.llvm.org
Sat Nov 11 02:00:42 PST 2023


Author: Nathan James
Date: 2023-11-11T09:56:33Z
New Revision: 0e55fef0e98ff5fc6898f3eda43e02143dbe0748

URL: https://github.com/llvm/llvm-project/commit/0e55fef0e98ff5fc6898f3eda43e02143dbe0748
DIFF: https://github.com/llvm/llvm-project/commit/0e55fef0e98ff5fc6898f3eda43e02143dbe0748.diff

LOG: [clang-tidy] Tweak diag ranges for bugprone-sizeof-expression

Provide more useful warning locations and diagnostic ranges.

Reviewed By: PiotrZSL

Differential Revision: https://reviews.llvm.org/D101617

Added: 
    

Modified: 
    clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp
    clang-tools-extra/clangd/test/diagnostics-tidy.test
    clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
    clang-tools-extra/test/clang-tidy/checkers/bugprone/sizeof-expression-warn-on-sizeof-pointer-to-aggregate.cpp
    clang-tools-extra/test/clang-tidy/checkers/bugprone/sizeof-expression.cpp

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp
index 62cde11ebb7399c..a1cffbc66619921 100644
--- a/clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp
@@ -192,10 +192,12 @@ void SizeofExpressionCheck::registerMatchers(MatchFinder *Finder) {
   }
 
   // Detect expression like: sizeof(expr, expr); most likely an error.
-  Finder->addMatcher(sizeOfExpr(has(ignoringParenImpCasts(
-                                    binaryOperator(hasOperatorName(",")))))
-                         .bind("sizeof-comma-expr"),
-                     this);
+  Finder->addMatcher(
+      sizeOfExpr(
+          has(ignoringParenImpCasts(
+              binaryOperator(hasOperatorName(",")).bind("sizeof-comma-binop"))))
+          .bind("sizeof-comma-expr"),
+      this);
 
   // Detect sizeof(...) /sizeof(...));
   // FIXME:
@@ -255,51 +257,62 @@ void SizeofExpressionCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(
       binaryOperator(
           hasAnyOperatorName("==", "!=", "<", "<=", ">", ">=", "+", "-"),
-          hasOperands(
-              anyOf(ignoringParenImpCasts(SizeOfExpr),
-                    ignoringParenImpCasts(binaryOperator(
-                        hasOperatorName("*"),
-                        hasEitherOperand(ignoringParenImpCasts(SizeOfExpr))))),
-              ignoringParenImpCasts(PtrDiffExpr)))
+          hasOperands(anyOf(ignoringParenImpCasts(
+                                SizeOfExpr.bind("sizeof-ptr-mul-expr")),
+                            ignoringParenImpCasts(binaryOperator(
+                                hasOperatorName("*"),
+                                hasEitherOperand(ignoringParenImpCasts(
+                                    SizeOfExpr.bind("sizeof-ptr-mul-expr")))))),
+                      ignoringParenImpCasts(PtrDiffExpr)))
           .bind("sizeof-in-ptr-arithmetic-mul"),
       this);
 
-  Finder->addMatcher(binaryOperator(hasOperatorName("/"),
-                                    hasLHS(ignoringParenImpCasts(PtrDiffExpr)),
-                                    hasRHS(ignoringParenImpCasts(SizeOfExpr)))
-                         .bind("sizeof-in-ptr-arithmetic-div"),
-                     this);
+  Finder->addMatcher(
+      binaryOperator(
+          hasOperatorName("/"), hasLHS(ignoringParenImpCasts(PtrDiffExpr)),
+          hasRHS(ignoringParenImpCasts(SizeOfExpr.bind("sizeof-ptr-div-expr"))))
+          .bind("sizeof-in-ptr-arithmetic-div"),
+      this);
 }
 
 void SizeofExpressionCheck::check(const MatchFinder::MatchResult &Result) {
   const ASTContext &Ctx = *Result.Context;
 
   if (const auto *E = Result.Nodes.getNodeAs<Expr>("sizeof-constant")) {
-    diag(E->getBeginLoc(),
-         "suspicious usage of 'sizeof(K)'; did you mean 'K'?");
+    diag(E->getBeginLoc(), "suspicious usage of 'sizeof(K)'; did you mean 'K'?")
+        << E->getSourceRange();
   } else if (const auto *E =
                  Result.Nodes.getNodeAs<Expr>("sizeof-integer-call")) {
     diag(E->getBeginLoc(), "suspicious usage of 'sizeof()' on an expression "
-                           "that results in an integer");
+                           "that results in an integer")
+        << E->getSourceRange();
   } else if (const auto *E = Result.Nodes.getNodeAs<Expr>("sizeof-this")) {
     diag(E->getBeginLoc(),
-         "suspicious usage of 'sizeof(this)'; did you mean 'sizeof(*this)'");
+         "suspicious usage of 'sizeof(this)'; did you mean 'sizeof(*this)'")
+        << E->getSourceRange();
   } else if (const auto *E = Result.Nodes.getNodeAs<Expr>("sizeof-charp")) {
     diag(E->getBeginLoc(),
-         "suspicious usage of 'sizeof(char*)'; do you mean 'strlen'?");
+         "suspicious usage of 'sizeof(char*)'; do you mean 'strlen'?")
+        << E->getSourceRange();
   } else if (const auto *E =
                  Result.Nodes.getNodeAs<Expr>("sizeof-pointer-to-aggregate")) {
     diag(E->getBeginLoc(),
-         "suspicious usage of 'sizeof(A*)'; pointer to aggregate");
-  } else if (const auto *E =
-                 Result.Nodes.getNodeAs<Expr>("sizeof-compare-constant")) {
-    diag(E->getBeginLoc(),
-         "suspicious comparison of 'sizeof(expr)' to a constant");
+         "suspicious usage of 'sizeof(A*)'; pointer to aggregate")
+        << E->getSourceRange();
+  } else if (const auto *E = Result.Nodes.getNodeAs<BinaryOperator>(
+                 "sizeof-compare-constant")) {
+    diag(E->getOperatorLoc(),
+         "suspicious comparison of 'sizeof(expr)' to a constant")
+        << E->getLHS()->getSourceRange() << E->getRHS()->getSourceRange();
   } else if (const auto *E =
                  Result.Nodes.getNodeAs<Expr>("sizeof-comma-expr")) {
-    diag(E->getBeginLoc(), "suspicious usage of 'sizeof(..., ...)'");
+    const auto *BO =
+        Result.Nodes.getNodeAs<BinaryOperator>("sizeof-comma-binop");
+    assert(BO);
+    diag(BO->getOperatorLoc(), "suspicious usage of 'sizeof(..., ...)'")
+        << E->getSourceRange();
   } else if (const auto *E =
-                 Result.Nodes.getNodeAs<Expr>("sizeof-divide-expr")) {
+                 Result.Nodes.getNodeAs<BinaryOperator>("sizeof-divide-expr")) {
     const auto *NumTy = Result.Nodes.getNodeAs<Type>("num-type");
     const auto *DenomTy = Result.Nodes.getNodeAs<Type>("denom-type");
     const auto *ElementTy = Result.Nodes.getNodeAs<Type>("elem-type");
@@ -311,49 +324,64 @@ void SizeofExpressionCheck::check(const MatchFinder::MatchResult &Result) {
 
     if (DenominatorSize > CharUnits::Zero() &&
         !NumeratorSize.isMultipleOf(DenominatorSize)) {
-      diag(E->getBeginLoc(), "suspicious usage of 'sizeof(...)/sizeof(...)';"
-                             " numerator is not a multiple of denominator");
+      diag(E->getOperatorLoc(), "suspicious usage of 'sizeof(...)/sizeof(...)';"
+                                " numerator is not a multiple of denominator")
+          << E->getLHS()->getSourceRange() << E->getRHS()->getSourceRange();
     } else if (ElementSize > CharUnits::Zero() &&
                DenominatorSize > CharUnits::Zero() &&
                ElementSize != DenominatorSize) {
-      diag(E->getBeginLoc(), "suspicious usage of 'sizeof(...)/sizeof(...)';"
-                             " numerator is not a multiple of denominator");
+      diag(E->getOperatorLoc(), "suspicious usage of 'sizeof(...)/sizeof(...)';"
+                                " numerator is not a multiple of denominator")
+          << E->getLHS()->getSourceRange() << E->getRHS()->getSourceRange();
     } else if (NumTy && DenomTy && NumTy == DenomTy) {
-      diag(E->getBeginLoc(),
-           "suspicious usage of sizeof pointer 'sizeof(T)/sizeof(T)'");
+      diag(E->getOperatorLoc(),
+           "suspicious usage of sizeof pointer 'sizeof(T)/sizeof(T)'")
+          << E->getLHS()->getSourceRange() << E->getRHS()->getSourceRange();
     } else if (PointedTy && DenomTy && PointedTy == DenomTy) {
-      diag(E->getBeginLoc(),
-           "suspicious usage of sizeof pointer 'sizeof(T*)/sizeof(T)'");
+      diag(E->getOperatorLoc(),
+           "suspicious usage of sizeof pointer 'sizeof(T*)/sizeof(T)'")
+          << E->getLHS()->getSourceRange() << E->getRHS()->getSourceRange();
     } else if (NumTy && DenomTy && NumTy->isPointerType() &&
                DenomTy->isPointerType()) {
-      diag(E->getBeginLoc(),
-           "suspicious usage of sizeof pointer 'sizeof(P*)/sizeof(Q*)'");
+      diag(E->getOperatorLoc(),
+           "suspicious usage of sizeof pointer 'sizeof(P*)/sizeof(Q*)'")
+          << E->getLHS()->getSourceRange() << E->getRHS()->getSourceRange();
     }
   } else if (const auto *E =
                  Result.Nodes.getNodeAs<Expr>("sizeof-sizeof-expr")) {
-    diag(E->getBeginLoc(), "suspicious usage of 'sizeof(sizeof(...))'");
-  } else if (const auto *E =
-                 Result.Nodes.getNodeAs<Expr>("sizeof-multiply-sizeof")) {
-    diag(E->getBeginLoc(), "suspicious 'sizeof' by 'sizeof' multiplication");
-  } else if (const auto *E =
-                 Result.Nodes.getNodeAs<Expr>("sizeof-in-ptr-arithmetic-mul")) {
+    diag(E->getBeginLoc(), "suspicious usage of 'sizeof(sizeof(...))'")
+        << E->getSourceRange();
+  } else if (const auto *E = Result.Nodes.getNodeAs<BinaryOperator>(
+                 "sizeof-multiply-sizeof")) {
+    diag(E->getOperatorLoc(), "suspicious 'sizeof' by 'sizeof' multiplication")
+        << E->getLHS()->getSourceRange() << E->getRHS()->getSourceRange();
+  } else if (const auto *E = Result.Nodes.getNodeAs<BinaryOperator>(
+                 "sizeof-in-ptr-arithmetic-mul")) {
     const auto *LPtrTy = Result.Nodes.getNodeAs<Type>("left-ptr-type");
     const auto *RPtrTy = Result.Nodes.getNodeAs<Type>("right-ptr-type");
     const auto *SizeofArgTy = Result.Nodes.getNodeAs<Type>("sizeof-arg-type");
+    const auto *SizeOfExpr =
+        Result.Nodes.getNodeAs<UnaryExprOrTypeTraitExpr>("sizeof-ptr-mul-expr");
 
     if ((LPtrTy == RPtrTy) && (LPtrTy == SizeofArgTy)) {
-      diag(E->getBeginLoc(), "suspicious usage of 'sizeof(...)' in "
-                              "pointer arithmetic");
+      diag(SizeOfExpr->getBeginLoc(), "suspicious usage of 'sizeof(...)' in "
+                                      "pointer arithmetic")
+          << SizeOfExpr->getSourceRange() << E->getOperatorLoc()
+          << E->getLHS()->getSourceRange() << E->getRHS()->getSourceRange();
     }
-  } else if (const auto *E =
-                 Result.Nodes.getNodeAs<Expr>("sizeof-in-ptr-arithmetic-div")) {
+  } else if (const auto *E = Result.Nodes.getNodeAs<BinaryOperator>(
+                 "sizeof-in-ptr-arithmetic-div")) {
     const auto *LPtrTy = Result.Nodes.getNodeAs<Type>("left-ptr-type");
     const auto *RPtrTy = Result.Nodes.getNodeAs<Type>("right-ptr-type");
     const auto *SizeofArgTy = Result.Nodes.getNodeAs<Type>("sizeof-arg-type");
+    const auto *SizeOfExpr =
+        Result.Nodes.getNodeAs<UnaryExprOrTypeTraitExpr>("sizeof-ptr-div-expr");
 
     if ((LPtrTy == RPtrTy) && (LPtrTy == SizeofArgTy)) {
-      diag(E->getBeginLoc(), "suspicious usage of 'sizeof(...)' in "
-                              "pointer arithmetic");
+      diag(SizeOfExpr->getBeginLoc(), "suspicious usage of 'sizeof(...)' in "
+                                      "pointer arithmetic")
+          << SizeOfExpr->getSourceRange() << E->getOperatorLoc()
+          << E->getLHS()->getSourceRange() << E->getRHS()->getSourceRange();
     }
   }
 }

diff  --git a/clang-tools-extra/clangd/test/diagnostics-tidy.test b/clang-tools-extra/clangd/test/diagnostics-tidy.test
index a100c9f4359d108..e592c9a0be7c357 100644
--- a/clang-tools-extra/clangd/test/diagnostics-tidy.test
+++ b/clang-tools-extra/clangd/test/diagnostics-tidy.test
@@ -14,7 +14,7 @@
 # CHECK-NEXT:        "message": "Suspicious usage of 'sizeof(K)'; did you mean 'K'?",
 # CHECK-NEXT:        "range": {
 # CHECK-NEXT:          "end": {
-# CHECK-NEXT:            "character": 12,
+# CHECK-NEXT:            "character": 16,
 # CHECK-NEXT:            "line": 1
 # CHECK-NEXT:          },
 # CHECK-NEXT:          "start": {

diff  --git a/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp b/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
index 14dd1f4b3f6d506..a52b647b0029b4f 100644
--- a/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
+++ b/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
@@ -305,7 +305,7 @@ TEST(DiagnosticsTest, ClangTidy) {
     int $main[[main]]() {
       int y = 4;
       return SQUARE($macroarg[[++]]y);
-      return $doubled[[sizeof]](sizeof(int));
+      return $doubled[[sizeof(sizeof(int))]];
     }
 
     // misc-no-recursion uses a custom traversal from the TUDecl

diff  --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/sizeof-expression-warn-on-sizeof-pointer-to-aggregate.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone/sizeof-expression-warn-on-sizeof-pointer-to-aggregate.cpp
index a49cd99eeb7dc3d..5ef2c46ffbdf134 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/sizeof-expression-warn-on-sizeof-pointer-to-aggregate.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/sizeof-expression-warn-on-sizeof-pointer-to-aggregate.cpp
@@ -68,9 +68,9 @@ int Test5() {
   sum += sizeof(A10) / sizeof(PtrArray[0]);
   // No warning.
   sum += sizeof(PC) / sizeof(PtrArray[0]);
-  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of sizeof pointer 'sizeof(T)/sizeof(T)'
+  // CHECK-MESSAGES: :[[@LINE-1]]:21: warning: suspicious usage of sizeof pointer 'sizeof(T)/sizeof(T)'
   sum += sizeof(ArrayC) / sizeof(PtrArray[0]);
-  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof(...)/sizeof(...)'; numerator is not a multiple of denominator
+  // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: suspicious usage of 'sizeof(...)/sizeof(...)'; numerator is not a multiple of denominator
 
   return sum;
 }

diff  --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/sizeof-expression.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone/sizeof-expression.cpp
index 0e6e87170352c46..003a02209c3d2de 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/sizeof-expression.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/sizeof-expression.cpp
@@ -77,7 +77,7 @@ int Test1(const char* ptr) {
   sum += sizeof(LEN + 1);
   // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof(K)'
   sum += sizeof(sum, LEN);
-  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof(..., ...)'
+  // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: suspicious usage of 'sizeof(..., ...)'
   sum += sizeof(AsBool());
   // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof()' on an expression that results in an integer
   sum += sizeof(AsInt());
@@ -103,41 +103,41 @@ int Test1(const char* ptr) {
   sum += sizeof(LEN + - + -sizeof(X));
   // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof(sizeof(...))'
   sum += sizeof(char) / sizeof(char);
-  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of sizeof pointer 'sizeof(T)/sizeof(T)'
+  // CHECK-MESSAGES: :[[@LINE-1]]:23: warning: suspicious usage of sizeof pointer 'sizeof(T)/sizeof(T)'
   sum += sizeof(A) / sizeof(S);
-  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof(...)/sizeof(...)'; numerator is not a multiple of denominator
+  // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: suspicious usage of 'sizeof(...)/sizeof(...)'; numerator is not a multiple of denominator
   sum += sizeof(char) / sizeof(int);
-  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof(...)/sizeof(...)'; numerator is not a multiple of denominator
+  // CHECK-MESSAGES: :[[@LINE-1]]:23: warning: suspicious usage of 'sizeof(...)/sizeof(...)'; numerator is not a multiple of denominator
   sum += sizeof(char) / sizeof(A);
-  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof(...)/sizeof(...)'; numerator is not a multiple of denominator
+  // CHECK-MESSAGES: :[[@LINE-1]]:23: warning: suspicious usage of 'sizeof(...)/sizeof(...)'; numerator is not a multiple of denominator
   sum += sizeof(B[0]) / sizeof(A);
-  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof(...)/sizeof(...)'; numerator is not a multiple of denominator
+  // CHECK-MESSAGES: :[[@LINE-1]]:23: warning: suspicious usage of 'sizeof(...)/sizeof(...)'; numerator is not a multiple of denominator
   sum += sizeof(ptr) / sizeof(char);
-  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of sizeof pointer 'sizeof(T*)/sizeof(T)'
+  // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: suspicious usage of sizeof pointer 'sizeof(T*)/sizeof(T)'
   sum += sizeof(ptr) / sizeof(ptr[0]);
-  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of sizeof pointer 'sizeof(T*)/sizeof(T)'
+  // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: suspicious usage of sizeof pointer 'sizeof(T*)/sizeof(T)'
   sum += sizeof(ptr) / sizeof(char*);
-  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of sizeof pointer 'sizeof(P*)/sizeof(Q*)'
+  // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: suspicious usage of sizeof pointer 'sizeof(P*)/sizeof(Q*)'
   sum += sizeof(ptr) / sizeof(void*);
-  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of sizeof pointer 'sizeof(P*)/sizeof(Q*)'
+  // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: suspicious usage of sizeof pointer 'sizeof(P*)/sizeof(Q*)'
   sum += sizeof(ptr) / sizeof(const void volatile*);
-  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of sizeof pointer 'sizeof(P*)/sizeof(Q*)'
+  // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: suspicious usage of sizeof pointer 'sizeof(P*)/sizeof(Q*)'
   sum += sizeof(ptr) / sizeof(char);
-  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of sizeof pointer 'sizeof(T*)/sizeof(T)'
+  // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: suspicious usage of sizeof pointer 'sizeof(T*)/sizeof(T)'
   sum += sizeof(ptr) / sizeof(ptr[0]);
-  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of sizeof pointer 'sizeof(T*)/sizeof(T)'
+  // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: suspicious usage of sizeof pointer 'sizeof(T*)/sizeof(T)'
   sum += sizeof(int) * sizeof(char);
-  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious 'sizeof' by 'sizeof' multiplication
+  // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: suspicious 'sizeof' by 'sizeof' multiplication
   sum += sizeof(ptr) * sizeof(ptr[0]);
-  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious 'sizeof' by 'sizeof' multiplication
+  // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: suspicious 'sizeof' by 'sizeof' multiplication
   sum += sizeof(int) * (2 * sizeof(char));
-  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious 'sizeof' by 'sizeof' multiplication
+  // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: suspicious 'sizeof' by 'sizeof' multiplication
   sum += (2 * sizeof(char)) * sizeof(int);
-  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious 'sizeof' by 'sizeof' multiplication
+  // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: suspicious 'sizeof' by 'sizeof' multiplication
   if (sizeof(A) < 0x100000) sum += 42;
-  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: suspicious comparison of 'sizeof(expr)' to a constant
+  // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: suspicious comparison of 'sizeof(expr)' to a constant
   if (sizeof(A) <= 0xFFFFFFFEU) sum += 42;
-  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: suspicious comparison of 'sizeof(expr)' to a constant
+  // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: suspicious comparison of 'sizeof(expr)' to a constant
   return sum;
 }
 
@@ -158,11 +158,11 @@ int CE4 = sizeof sizeof(MyConstChar);
 int Test2(MyConstChar* A) {
   int sum = 0;
   sum += sizeof(MyConstChar) / sizeof(char);
-  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of sizeof pointer 'sizeof(T)/sizeof(T)'
+  // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: suspicious usage of sizeof pointer 'sizeof(T)/sizeof(T)'
   sum += sizeof(MyConstChar) / sizeof(MyChar);
-  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of sizeof pointer 'sizeof(T)/sizeof(T)'
+  // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: suspicious usage of sizeof pointer 'sizeof(T)/sizeof(T)'
   sum += sizeof(A[0]) / sizeof(char);
-  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of sizeof pointer 'sizeof(T)/sizeof(T)'
+  // CHECK-MESSAGES: :[[@LINE-1]]:23: warning: suspicious usage of sizeof pointer 'sizeof(T)/sizeof(T)'
   return sum;
 }
 
@@ -171,7 +171,7 @@ int Foo() { int A[T]; return sizeof(T); }
 // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: suspicious usage of 'sizeof(K)'
 template <typename T>
 int Bar() { T A[5]; return sizeof(A[0]) / sizeof(T); }
-// CHECK-MESSAGES: :[[@LINE-1]]:28: warning: suspicious usage of sizeof pointer 'sizeof(T)/sizeof(T)'
+// CHECK-MESSAGES: :[[@LINE-1]]:41: warning: suspicious usage of sizeof pointer 'sizeof(T)/sizeof(T)'
 int Test3() { return Foo<42>() + Bar<char>(); }
 
 static const char* kABC = "abc";
@@ -246,10 +246,10 @@ int Test5() {
   // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: suspicious usage of 'sizeof(A*)'; pointer to aggregate
   sum += sizeof(PC) / sizeof(PtrArray[0]);
   // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof(A*)'; pointer to aggregate
-  // CHECK-MESSAGES: :[[@LINE-2]]:10: warning: suspicious usage of sizeof pointer 'sizeof(T)/sizeof(T)'
+  // CHECK-MESSAGES: :[[@LINE-2]]:21: warning: suspicious usage of sizeof pointer 'sizeof(T)/sizeof(T)'
   // CHECK-MESSAGES: :[[@LINE-3]]:23: warning: suspicious usage of 'sizeof(A*)'; pointer to aggregate
   sum += sizeof(ArrayC) / sizeof(PtrArray[0]);
-  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof(...)/sizeof(...)'; numerator is not a multiple of denominator
+  // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: suspicious usage of 'sizeof(...)/sizeof(...)'; numerator is not a multiple of denominator
   // CHECK-MESSAGES: :[[@LINE-2]]:27: warning: suspicious usage of 'sizeof(A*)'; pointer to aggregate
 
   return sum;
@@ -263,34 +263,34 @@ int Test6() {
   sum += sizeof(struct S) == P - Q;
   // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof(...)' in pointer arithmetic
   sum += 5 * sizeof(S) != P - Q;
-  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof(...)' in pointer arithmetic
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: suspicious usage of 'sizeof(...)' in pointer arithmetic
   sum += sizeof(S) < P - Q;
   // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof(...)' in pointer arithmetic
   sum += 5 * sizeof(S) <= P - Q;
-  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof(...)' in pointer arithmetic
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: suspicious usage of 'sizeof(...)' in pointer arithmetic
   sum += 5 * sizeof(*P) >= P - Q;
-  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof(...)' in pointer arithmetic
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: suspicious usage of 'sizeof(...)' in pointer arithmetic
   sum += Q - P > 3 * sizeof(*P);
-  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof(...)' in pointer arithmetic
+  // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: suspicious usage of 'sizeof(...)' in pointer arithmetic
   sum += sizeof(S) + (P - Q);
   // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof(...)' in pointer arithmetic
   sum += 5 * sizeof(S) - (P - Q);
-  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof(...)' in pointer arithmetic
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: suspicious usage of 'sizeof(...)' in pointer arithmetic
   sum += (P - Q) / sizeof(S);
-  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof(...)' in pointer arithmetic
+  // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: suspicious usage of 'sizeof(...)' in pointer arithmetic
   sum += (P - Q) / sizeof(*Q);
-  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof(...)' in pointer arithmetic
+  // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: suspicious usage of 'sizeof(...)' in pointer arithmetic
 
   return sum;
 }
 
 #ifdef __SIZEOF_INT128__
-template <__int128_t N> 
+template <__int128_t N>
 #else
 template <long N> // Fallback for platforms which do not define `__int128_t`
 #endif
 bool Baz() { return sizeof(A) < N; }
-// CHECK-MESSAGES: :[[@LINE-1]]:21: warning: suspicious comparison of 'sizeof(expr)' to a constant
+// CHECK-MESSAGES: :[[@LINE-1]]:31: warning: suspicious comparison of 'sizeof(expr)' to a constant
 bool Test7() { return Baz<-1>(); }
 
 int ValidExpressions() {


        


More information about the cfe-commits mailing list