[clang-tools-extra] 42ce00e - [clang-tidy] Simplify suspicious memset usage check
Stephen Kelly via cfe-commits
cfe-commits at lists.llvm.org
Sat Feb 27 04:17:31 PST 2021
Author: Stephen Kelly
Date: 2021-02-27T12:17:09Z
New Revision: 42ce00ec3947de89c1cda0138fe6adffeeeeace3
URL: https://github.com/llvm/llvm-project/commit/42ce00ec3947de89c1cda0138fe6adffeeeeace3
DIFF: https://github.com/llvm/llvm-project/commit/42ce00ec3947de89c1cda0138fe6adffeeeeace3.diff
LOG: [clang-tidy] Simplify suspicious memset usage check
Differential Revision: https://reviews.llvm.org/D97150
Added:
Modified:
clang-tools-extra/clang-tidy/bugprone/SuspiciousMemsetUsageCheck.cpp
clang-tools-extra/clang-tidy/bugprone/SuspiciousMemsetUsageCheck.h
Removed:
################################################################################
diff --git a/clang-tools-extra/clang-tidy/bugprone/SuspiciousMemsetUsageCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/SuspiciousMemsetUsageCheck.cpp
index 37748d9fa8cc..341ba6ccc09f 100644
--- a/clang-tools-extra/clang-tidy/bugprone/SuspiciousMemsetUsageCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/SuspiciousMemsetUsageCheck.cpp
@@ -35,27 +35,24 @@ void SuspiciousMemsetUsageCheck::registerMatchers(MatchFinder *Finder) {
callee(MemsetDecl),
hasArgument(1, characterLiteral(equals(static_cast<unsigned>('0')))
.bind("char-zero-fill")),
- unless(
- eachOf(hasArgument(0, anyOf(hasType(pointsTo(isAnyCharacter())),
- hasType(arrayType(hasElementType(
- isAnyCharacter()))))),
- isInTemplateInstantiation()))),
+ unless(hasArgument(
+ 0, anyOf(hasType(pointsTo(isAnyCharacter())),
+ hasType(arrayType(hasElementType(isAnyCharacter()))))))),
this);
// Look for memset with an integer literal in its fill_char argument.
// Will check if it gets truncated.
- Finder->addMatcher(callExpr(callee(MemsetDecl),
- hasArgument(1, integerLiteral().bind("num-fill")),
- unless(isInTemplateInstantiation())),
- this);
+ Finder->addMatcher(
+ callExpr(callee(MemsetDecl),
+ hasArgument(1, integerLiteral().bind("num-fill"))),
+ this);
// Look for memset(x, y, 0) as that is most likely an argument swap.
Finder->addMatcher(
callExpr(callee(MemsetDecl),
unless(hasArgument(1, anyOf(characterLiteral(equals(
static_cast<unsigned>('0'))),
- integerLiteral()))),
- unless(isInTemplateInstantiation()))
+ integerLiteral()))))
.bind("call"),
this);
}
diff --git a/clang-tools-extra/clang-tidy/bugprone/SuspiciousMemsetUsageCheck.h b/clang-tools-extra/clang-tidy/bugprone/SuspiciousMemsetUsageCheck.h
index 40746413485f..0a46f0620ef8 100644
--- a/clang-tools-extra/clang-tidy/bugprone/SuspiciousMemsetUsageCheck.h
+++ b/clang-tools-extra/clang-tidy/bugprone/SuspiciousMemsetUsageCheck.h
@@ -25,6 +25,9 @@ class SuspiciousMemsetUsageCheck : public ClangTidyCheck {
: ClangTidyCheck(Name, Context) {}
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+ llvm::Optional<TraversalKind> getCheckTraversalKind() const override {
+ return TK_IgnoreUnlessSpelledInSource;
+ }
};
} // namespace bugprone
More information about the cfe-commits
mailing list