]> granicus.if.org Git - clang/commitdiff
[ASTMatchers] Improve assert message for broken parent map.
authorSam McCall <sam.mccall@gmail.com>
Tue, 8 Jan 2019 07:29:46 +0000 (07:29 +0000)
committerSam McCall <sam.mccall@gmail.com>
Tue, 8 Jan 2019 07:29:46 +0000 (07:29 +0000)
Summary:
This assert catches places where the AST (as seen by RecursiveASTVisitor)
becomes disconnected due to incomplete traversal.
Making it print the actual parent-less node is a lot more helpful - it's
possible to work out which part of the tree wasn't traversed.

Reviewers: ilya-biryukov

Subscribers: cfe-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@350612 91177308-0d34-0410-b5e6-96231b3b80d8

lib/ASTMatchers/ASTMatchFinder.cpp

index 32d8282f6df62b13cda33aa246872ff2b897ed2f..dec2e2ad1f939cdb0c1021136e1eaf07f310aa18 100644 (file)
@@ -676,13 +676,17 @@ private:
       //  c) there is a bug in the AST, and the node is not reachable
       // Usually the traversal scope is the whole AST, which precludes b.
       // Bugs are common enough that it's worthwhile asserting when we can.
-      assert((Node.get<TranslationUnitDecl>() ||
-              /* Traversal scope is limited if none of the bounds are the TU */
-              llvm::none_of(ActiveASTContext->getTraversalScope(),
-                            [](Decl *D) {
-                              return D->getKind() == Decl::TranslationUnit;
-                            })) &&
-             "Found node that is not in the complete parent map!");
+#ifndef NDEBUG
+      if (!Node.get<TranslationUnitDecl>() &&
+          /* Traversal scope is full AST if any of the bounds are the TU */
+          llvm::any_of(ActiveASTContext->getTraversalScope(), [](Decl *D) {
+            return D->getKind() == Decl::TranslationUnit;
+          })) {
+        llvm::errs() << "Tried to match orphan node:\n";
+        Node.dump(llvm::errs(), ActiveASTContext->getSourceManager());
+        llvm_unreachable("Parent map should be complete!");
+      }
+#endif
       return false;
     }
     if (Parents.size() == 1) {