https://github.com/mizvekov created https://github.com/llvm/llvm-project/pull/142654
This matcher would never match anything, because all record types as-written would be wrappen in an ElaboratedType. Just fixing that leads to a matcher which has too many false positives to be useful. The warning message itself is not great either, it has a hard-coded type name. >From f4e222ad64ce5edeadbaed5adceedff40043dcd0 Mon Sep 17 00:00:00 2001 From: Matheus Izvekov <mizve...@gmail.com> Date: Tue, 3 Jun 2025 15:48:41 -0300 Subject: [PATCH] [clang-tidy] NFCI: remove non-functional matcher from SizeofExpressionCheck This matcher would never match anything, because all record types as-written would be wrappen in an ElaboratedType. Just fixing that leads to a matcher which has too many false positives to be useful. The warning message itself is not great either, it has a hard-coded type name. --- .../bugprone/SizeofExpressionCheck.cpp | 25 ++++++------------- 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp index f3d4c2255d86e..9eeba867f5211 100644 --- a/clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp @@ -170,8 +170,6 @@ void SizeofExpressionCheck::registerMatchers(MatchFinder *Finder) { const auto PointerToStructType = hasUnqualifiedDesugaredType(pointerType(pointee(recordType()))); - const auto PointerToStructTypeWithBinding = - type(PointerToStructType).bind("struct-type"); const auto PointerToStructExpr = expr(hasType(hasCanonicalType(PointerToStructType))); @@ -188,12 +186,10 @@ void SizeofExpressionCheck::registerMatchers(MatchFinder *Finder) { ignoringParenImpCasts(unaryOperator(hasOperatorName("*"))); Finder->addMatcher( - expr(sizeOfExpr(anyOf(has(ignoringParenImpCasts( - expr(PointerToDetectedExpr, unless(DerefExpr), - unless(SubscriptExprWithZeroIndex), - unless(VarWithConstStrLiteralDecl), - unless(cxxThisExpr())))), - has(PointerToStructTypeWithBinding)))) + expr(sizeOfExpr(has(ignoringParenImpCasts(expr( + PointerToDetectedExpr, unless(DerefExpr), + unless(SubscriptExprWithZeroIndex), + unless(VarWithConstStrLiteralDecl), unless(cxxThisExpr())))))) .bind("sizeof-pointer"), this); } @@ -354,16 +350,9 @@ void SizeofExpressionCheck::check(const MatchFinder::MatchResult &Result) { "suspicious usage of 'sizeof(char*)'; do you mean 'strlen'?") << E->getSourceRange(); } else if (const auto *E = Result.Nodes.getNodeAs<Expr>("sizeof-pointer")) { - if (Result.Nodes.getNodeAs<Type>("struct-type")) { - diag(E->getBeginLoc(), - "suspicious usage of 'sizeof(A*)' on pointer-to-aggregate type; did " - "you mean 'sizeof(A)'?") - << E->getSourceRange(); - } else { - diag(E->getBeginLoc(), "suspicious usage of 'sizeof()' on an expression " - "of pointer type") - << E->getSourceRange(); - } + diag(E->getBeginLoc(), "suspicious usage of 'sizeof()' on an expression " + "of pointer type") + << E->getSourceRange(); } else if (const auto *E = Result.Nodes.getNodeAs<BinaryOperator>( "sizeof-compare-constant")) { diag(E->getOperatorLoc(), _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits