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
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) {
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