[PATCH] D93324: Avoid isImplicit call on object which could be nullptr

Stephen Kelly via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Dec 15 15:27:59 PST 2020


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG702f822ca5bb: [ASTMatcher] Avoid isImplicit call on object which could be nullptr (authored by stephenkelly).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D93324/new/

https://reviews.llvm.org/D93324

Files:
  clang/include/clang/ASTMatchers/ASTMatchersInternal.h
  clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp


Index: clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
===================================================================
--- clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
@@ -1935,6 +1935,18 @@
       matches(Code, callExpr(traverse(TK_IgnoreUnlessSpelledInSource,
                                       hasAnyArgument(floatLiteral())))));
 
+  EXPECT_TRUE(matches(
+      R"cpp(
+void takesBool(bool){}
+
+template <typename T>
+void neverInstantiatedTemplate() {
+  takesBool(T{});
+}
+)cpp",
+      traverse(TK_IgnoreUnlessSpelledInSource,
+               callExpr(unless(callExpr(hasDeclaration(functionDecl())))))));
+
   EXPECT_TRUE(
       matches(VarDeclCode, varDecl(traverse(TK_IgnoreUnlessSpelledInSource,
                                             hasType(builtinType())))));
Index: clang/include/clang/ASTMatchers/ASTMatchersInternal.h
===================================================================
--- clang/include/clang/ASTMatchers/ASTMatchersInternal.h
+++ clang/include/clang/ASTMatchers/ASTMatchersInternal.h
@@ -1064,10 +1064,11 @@
   /// is \c NULL.
   bool matchesDecl(const Decl *Node, ASTMatchFinder *Finder,
                    BoundNodesTreeBuilder *Builder) const {
-    if (Finder->isTraversalIgnoringImplicitNodes() && Node->isImplicit())
-      return false;
-    return Node != nullptr && this->InnerMatcher.matches(
-                                  DynTypedNode::create(*Node), Finder, Builder);
+    return Node != nullptr &&
+           !(Finder->isTraversalIgnoringImplicitNodes() &&
+             Node->isImplicit()) &&
+           this->InnerMatcher.matches(DynTypedNode::create(*Node), Finder,
+                                      Builder);
   }
 };
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D93324.312056.patch
Type: text/x-patch
Size: 1784 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20201215/aaf7049c/attachment-0001.bin>


More information about the cfe-commits mailing list