diff --git a/clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp index 62cde11ebb739..a1cffbc666199 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("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("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("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("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("sizeof-pointer-to-aggregate")) { diag(E->getBeginLoc(), - "suspicious usage of 'sizeof(A*)'; pointer to aggregate"); - } else if (const auto *E = - Result.Nodes.getNodeAs("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( + "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("sizeof-comma-expr")) { - diag(E->getBeginLoc(), "suspicious usage of 'sizeof(..., ...)'"); + const auto *BO = + Result.Nodes.getNodeAs("sizeof-comma-binop"); + assert(BO); + diag(BO->getOperatorLoc(), "suspicious usage of 'sizeof(..., ...)'") + << E->getSourceRange(); } else if (const auto *E = - Result.Nodes.getNodeAs("sizeof-divide-expr")) { + Result.Nodes.getNodeAs("sizeof-divide-expr")) { const auto *NumTy = Result.Nodes.getNodeAs("num-type"); const auto *DenomTy = Result.Nodes.getNodeAs("denom-type"); const auto *ElementTy = Result.Nodes.getNodeAs("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("sizeof-sizeof-expr")) { - diag(E->getBeginLoc(), "suspicious usage of 'sizeof(sizeof(...))'"); - } else if (const auto *E = - Result.Nodes.getNodeAs("sizeof-multiply-sizeof")) { - diag(E->getBeginLoc(), "suspicious 'sizeof' by 'sizeof' multiplication"); - } else if (const auto *E = - Result.Nodes.getNodeAs("sizeof-in-ptr-arithmetic-mul")) { + diag(E->getBeginLoc(), "suspicious usage of 'sizeof(sizeof(...))'") + << E->getSourceRange(); + } else if (const auto *E = Result.Nodes.getNodeAs( + "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( + "sizeof-in-ptr-arithmetic-mul")) { const auto *LPtrTy = Result.Nodes.getNodeAs("left-ptr-type"); const auto *RPtrTy = Result.Nodes.getNodeAs("right-ptr-type"); const auto *SizeofArgTy = Result.Nodes.getNodeAs("sizeof-arg-type"); + const auto *SizeOfExpr = + Result.Nodes.getNodeAs("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("sizeof-in-ptr-arithmetic-div")) { + } else if (const auto *E = Result.Nodes.getNodeAs( + "sizeof-in-ptr-arithmetic-div")) { const auto *LPtrTy = Result.Nodes.getNodeAs("left-ptr-type"); const auto *RPtrTy = Result.Nodes.getNodeAs("right-ptr-type"); const auto *SizeofArgTy = Result.Nodes.getNodeAs("sizeof-arg-type"); + const auto *SizeOfExpr = + Result.Nodes.getNodeAs("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 a100c9f4359d1..e592c9a0be7c3 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 14dd1f4b3f6d5..a52b647b0029b 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 a49cd99eeb7dc..5ef2c46ffbdf1 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 0e6e87170352c..003a02209c3d2 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 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(); } 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 // 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() {