[clang-tidy] llvm-twine-local ignores parameters
authorNathan James <n.james93@hotmail.co.uk>
Mon, 22 Jun 2020 17:25:44 +0000 (18:25 +0100)
committerNathan James <n.james93@hotmail.co.uk>
Mon, 22 Jun 2020 17:25:45 +0000 (18:25 +0100)
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

clang-tools-extra/clang-tidy/llvm/TwineLocalCheck.cpp
clang-tools-extra/test/clang-tidy/checkers/llvm-twine-local.cpp

index 63a9314..907bdcb 100644 (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) {
index 06eb761..3dcf6ab 100644 (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