[PATCH] D97150: [clang-tidy] Simplify suspicious memset usage check
Stephen Kelly via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sat Feb 27 04:17:39 PST 2021
This revision was automatically updated to reflect the committed changes.
Closed by commit rG42ce00ec3947: [clang-tidy] Simplify suspicious memset usage check (authored by stephenkelly).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D97150/new/
https://reviews.llvm.org/D97150
Files:
clang-tools-extra/clang-tidy/bugprone/SuspiciousMemsetUsageCheck.cpp
clang-tools-extra/clang-tidy/bugprone/SuspiciousMemsetUsageCheck.h
Index: clang-tools-extra/clang-tidy/bugprone/SuspiciousMemsetUsageCheck.h
===================================================================
--- clang-tools-extra/clang-tidy/bugprone/SuspiciousMemsetUsageCheck.h
+++ clang-tools-extra/clang-tidy/bugprone/SuspiciousMemsetUsageCheck.h
@@ -25,6 +25,9 @@
: 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
Index: clang-tools-extra/clang-tidy/bugprone/SuspiciousMemsetUsageCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/bugprone/SuspiciousMemsetUsageCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/SuspiciousMemsetUsageCheck.cpp
@@ -35,27 +35,24 @@
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);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D97150.326897.patch
Type: text/x-patch
Size: 2602 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210227/d316a3b8/attachment-0001.bin>
More information about the cfe-commits
mailing list