[clang-tidy] llvm-twine-local ignores parameters

Ignore paramater declarations of type `::llvm::Twine`, These don't suffer the same use after free risks as local twines.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D82281
This commit is contained in:
Nathan James 2020-06-22 18:25:44 +01:00
parent 37fb860301
commit 9a8b041144
No known key found for this signature in database
GPG Key ID: CC007AFCDA90AA5F
2 changed files with 5 additions and 2 deletions

View File

@ -19,8 +19,10 @@ namespace llvm_check {
void TwineLocalCheck::registerMatchers(MatchFinder *Finder) {
auto TwineType =
qualType(hasDeclaration(recordDecl(hasName("::llvm::Twine"))));
Finder->addMatcher(varDecl(hasType(TwineType)).bind("variable"), this);
qualType(hasDeclaration(cxxRecordDecl(hasName("::llvm::Twine"))));
Finder->addMatcher(
varDecl(unless(parmVarDecl()), hasType(TwineType)).bind("variable"),
this);
}
void TwineLocalCheck::check(const MatchFinder::MatchResult &Result) {

View File

@ -13,6 +13,7 @@ public:
using namespace llvm;
void foo(const Twine &x);
void bar(Twine x);
static Twine Moo = Twine("bark") + "bah";
// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: twine variables are prone to use-after-free bugs