-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[clang-tidy] NFCI: remove non-functional matcher from SizeofExpressionCheck #142654
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[clang-tidy] NFCI: remove non-functional matcher from SizeofExpressionCheck #142654
Conversation
…nCheck 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.
@llvm/pr-subscribers-clang-tidy Author: Matheus Izvekov (mizvekov) ChangesThis 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:
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(),
|
@llvm/pr-subscribers-clang-tools-extra Author: Matheus Izvekov (mizvekov) ChangesThis 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:
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(),
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
maybe wait for the other reviewer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, if all tests pass then this must be dead code! Thanks for cleaning up.
This matcher would never match anything, because all record types as-written would be wrapped 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.