Skip to content

Commit 4c59ab3

Browse files
committed
[clang-tidy][NFC] Simplify a lot of bugprone-sizeof-expression matchers
There should be a follow up to this for changing the traversal mode, but some of the tests don't like that. Reviewed By: steveire Differential Revision: https://reviews.llvm.org/D101614
1 parent c6b96ae commit 4c59ab3

File tree

1 file changed

+11
-18
lines changed

1 file changed

+11
-18
lines changed

clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,8 @@ void SizeofExpressionCheck::registerMatchers(MatchFinder *Finder) {
9090
const auto IntegerCallExpr = ignoringParenImpCasts(
9191
callExpr(anyOf(hasType(isInteger()), hasType(enumType())),
9292
unless(isInTemplateInstantiation())));
93-
const auto SizeOfExpr = expr(anyOf(
94-
sizeOfExpr(
95-
has(hasUnqualifiedDesugaredType(type().bind("sizeof-arg-type")))),
96-
sizeOfExpr(has(expr(hasType(
97-
hasUnqualifiedDesugaredType(type().bind("sizeof-arg-type"))))))));
93+
const auto SizeOfExpr = sizeOfExpr(hasArgumentOfType(
94+
hasUnqualifiedDesugaredType(type().bind("sizeof-arg-type"))));
9895
const auto SizeOfZero =
9996
sizeOfExpr(has(ignoringParenImpCasts(integerLiteral(equals(0)))));
10097

@@ -184,9 +181,8 @@ void SizeofExpressionCheck::registerMatchers(MatchFinder *Finder) {
184181
Finder->addMatcher(
185182
binaryOperator(matchers::isRelationalOperator(),
186183
hasOperands(ignoringParenImpCasts(SizeOfExpr),
187-
ignoringParenImpCasts(anyOf(
188-
integerLiteral(equals(0)),
189-
integerLiteral(isBiggerThan(0x80000))))))
184+
ignoringParenImpCasts(integerLiteral(anyOf(
185+
equals(0), isBiggerThan(0x80000))))))
190186
.bind("sizeof-compare-constant"),
191187
this);
192188
}
@@ -207,18 +203,15 @@ void SizeofExpressionCheck::registerMatchers(MatchFinder *Finder) {
207203
const auto ElemType =
208204
arrayType(hasElementType(recordType().bind("elem-type")));
209205
const auto ElemPtrType = pointerType(pointee(type().bind("elem-ptr-type")));
210-
const auto NumType = hasCanonicalType(
211-
type(anyOf(ElemType, ElemPtrType, type())).bind("num-type"));
212-
const auto DenomType = hasCanonicalType(type().bind("denom-type"));
213206

214207
Finder->addMatcher(
215-
binaryOperator(hasOperatorName("/"),
216-
hasLHS(expr(ignoringParenImpCasts(
217-
anyOf(sizeOfExpr(has(NumType)),
218-
sizeOfExpr(has(expr(hasType(NumType)))))))),
219-
hasRHS(expr(ignoringParenImpCasts(
220-
anyOf(sizeOfExpr(has(DenomType)),
221-
sizeOfExpr(has(expr(hasType(DenomType)))))))))
208+
binaryOperator(
209+
hasOperatorName("/"),
210+
hasLHS(ignoringParenImpCasts(sizeOfExpr(hasArgumentOfType(
211+
hasCanonicalType(type(anyOf(ElemType, ElemPtrType, type()))
212+
.bind("num-type")))))),
213+
hasRHS(ignoringParenImpCasts(sizeOfExpr(
214+
hasArgumentOfType(hasCanonicalType(type().bind("denom-type")))))))
222215
.bind("sizeof-divide-expr"),
223216
this);
224217

0 commit comments

Comments
 (0)