[clang-tools-extra] 9a8b041 - [clang-tidy] llvm-twine-local ignores parameters
Nathan James via cfe-commits
cfe-commits at lists.llvm.org
Mon Jun 22 10:25:58 PDT 2020
Author: Nathan James
Date: 2020-06-22T18:25:45+01:00
New Revision: 9a8b0411448062e7231a0ee26bd14a3d1c097e9e
URL: https://github.com/llvm/llvm-project/commit/9a8b0411448062e7231a0ee26bd14a3d1c097e9e
DIFF: https://github.com/llvm/llvm-project/commit/9a8b0411448062e7231a0ee26bd14a3d1c097e9e.diff
LOG: [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
Added:
Modified:
clang-tools-extra/clang-tidy/llvm/TwineLocalCheck.cpp
clang-tools-extra/test/clang-tidy/checkers/llvm-twine-local.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clang-tidy/llvm/TwineLocalCheck.cpp b/clang-tools-extra/clang-tidy/llvm/TwineLocalCheck.cpp
index 63a9314a49e5..907bdcb264bf 100644
--- a/clang-tools-extra/clang-tidy/llvm/TwineLocalCheck.cpp
+++ b/clang-tools-extra/clang-tidy/llvm/TwineLocalCheck.cpp
@@ -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) {
diff --git a/clang-tools-extra/test/clang-tidy/checkers/llvm-twine-local.cpp b/clang-tools-extra/test/clang-tidy/checkers/llvm-twine-local.cpp
index 06eb7613d439..3dcf6abe0c22 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/llvm-twine-local.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/llvm-twine-local.cpp
@@ -13,6 +13,7 @@ class Twine {
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
More information about the cfe-commits
mailing list