[clang-tools-extra] 3b1e3d2 - [clang-tidy] Fix an unused-raii check crash on objective-c++.

Haojian Wu via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 7 04:37:06 PDT 2020


Author: Haojian Wu
Date: 2020-07-07T13:36:20+02:00
New Revision: 3b1e3d22735b37eea3ce52d655009f5cd4ad2262

URL: https://github.com/llvm/llvm-project/commit/3b1e3d22735b37eea3ce52d655009f5cd4ad2262
DIFF: https://github.com/llvm/llvm-project/commit/3b1e3d22735b37eea3ce52d655009f5cd4ad2262.diff

LOG: [clang-tidy] Fix an unused-raii check crash on objective-c++.

Differential Revision: https://reviews.llvm.org/D83293

Added: 
    clang-tools-extra/test/clang-tidy/checkers/bugprone-unused-raii-crash.mm

Modified: 
    clang-tools-extra/clang-tidy/bugprone/UnusedRaiiCheck.cpp

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/clang-tidy/bugprone/UnusedRaiiCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/UnusedRaiiCheck.cpp
index 34a489e324e4..70ce413d20ff 100644
--- a/clang-tools-extra/clang-tidy/bugprone/UnusedRaiiCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/UnusedRaiiCheck.cpp
@@ -27,9 +27,10 @@ void UnusedRaiiCheck::registerMatchers(MatchFinder *Finder) {
   // Look for temporaries that are constructed in-place and immediately
   // destroyed. Look for temporaries created by a functional cast but not for
   // those returned from a call.
-  auto BindTemp =
-      cxxBindTemporaryExpr(unless(has(ignoringParenImpCasts(callExpr()))))
-          .bind("temp");
+  auto BindTemp = cxxBindTemporaryExpr(
+                      unless(has(ignoringParenImpCasts(callExpr()))),
+                      unless(has(ignoringParenImpCasts(objcMessageExpr()))))
+                      .bind("temp");
   Finder->addMatcher(
       traverse(ast_type_traits::TK_AsIs,
                exprWithCleanups(
@@ -79,6 +80,7 @@ void UnusedRaiiCheck::check(const MatchFinder::MatchResult &Result) {
   auto Matches =
       match(expr(hasDescendant(typeLoc().bind("t"))), *E, *Result.Context);
   const auto *TL = selectFirst<TypeLoc>("t", Matches);
+  assert(TL);
   D << FixItHint::CreateInsertion(
       Lexer::getLocForEndOfToken(TL->getEndLoc(), 0, *Result.SourceManager,
                                  getLangOpts()),

diff  --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone-unused-raii-crash.mm b/clang-tools-extra/test/clang-tidy/checkers/bugprone-unused-raii-crash.mm
new file mode 100644
index 000000000000..432fd5329c56
--- /dev/null
+++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone-unused-raii-crash.mm
@@ -0,0 +1,15 @@
+// RUN: clang-tidy %s -checks=-*,bugprone-unused-raii -- | count 0
+
+struct CxxClass {
+  ~CxxClass() {}
+};
+
+ at interface ObjcClass {
+}
+- (CxxClass)set:(int)p;
+ at end
+
+void test(ObjcClass *s) {
+  [s set:1]; // ok, no crash, no diagnostic emitted.
+  return;
+}


        


More information about the cfe-commits mailing list