Skip to content

Commit 42ce00e

Browse files
committed
[clang-tidy] Simplify suspicious memset usage check
Differential Revision: https://reviews.llvm.org/D97150
1 parent 302cc84 commit 42ce00e

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

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

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,27 +35,24 @@ void SuspiciousMemsetUsageCheck::registerMatchers(MatchFinder *Finder) {
3535
callee(MemsetDecl),
3636
hasArgument(1, characterLiteral(equals(static_cast<unsigned>('0')))
3737
.bind("char-zero-fill")),
38-
unless(
39-
eachOf(hasArgument(0, anyOf(hasType(pointsTo(isAnyCharacter())),
40-
hasType(arrayType(hasElementType(
41-
isAnyCharacter()))))),
42-
isInTemplateInstantiation()))),
38+
unless(hasArgument(
39+
0, anyOf(hasType(pointsTo(isAnyCharacter())),
40+
hasType(arrayType(hasElementType(isAnyCharacter()))))))),
4341
this);
4442

4543
// Look for memset with an integer literal in its fill_char argument.
4644
// Will check if it gets truncated.
47-
Finder->addMatcher(callExpr(callee(MemsetDecl),
48-
hasArgument(1, integerLiteral().bind("num-fill")),
49-
unless(isInTemplateInstantiation())),
50-
this);
45+
Finder->addMatcher(
46+
callExpr(callee(MemsetDecl),
47+
hasArgument(1, integerLiteral().bind("num-fill"))),
48+
this);
5149

5250
// Look for memset(x, y, 0) as that is most likely an argument swap.
5351
Finder->addMatcher(
5452
callExpr(callee(MemsetDecl),
5553
unless(hasArgument(1, anyOf(characterLiteral(equals(
5654
static_cast<unsigned>('0'))),
57-
integerLiteral()))),
58-
unless(isInTemplateInstantiation()))
55+
integerLiteral()))))
5956
.bind("call"),
6057
this);
6158
}

clang-tools-extra/clang-tidy/bugprone/SuspiciousMemsetUsageCheck.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ class SuspiciousMemsetUsageCheck : public ClangTidyCheck {
2525
: ClangTidyCheck(Name, Context) {}
2626
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
2727
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
28+
llvm::Optional<TraversalKind> getCheckTraversalKind() const override {
29+
return TK_IgnoreUnlessSpelledInSource;
30+
}
2831
};
2932

3033
} // namespace bugprone

0 commit comments

Comments
 (0)