[clang-tools-extra] [clang-tidy] NFCI: remove non-functional matcher from SizeofExpressionCheck (PR #142654)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Jun 3 11:56:55 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-tidy
Author: Matheus Izvekov (mizvekov)
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/142654.diff
1 Files Affected:
- (modified) clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp (+7-18)
``````````diff
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(),
``````````
</details>
https://github.com/llvm/llvm-project/pull/142654
More information about the cfe-commits
mailing list