sammccall created this revision. sammccall added a reviewer: ilya-biryukov. Herald added a subscriber: cfe-commits.
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. Repository: rC Clang https://reviews.llvm.org/D56395 Files: lib/ASTMatchers/ASTMatchFinder.cpp Index: lib/ASTMatchers/ASTMatchFinder.cpp =================================================================== --- lib/ASTMatchers/ASTMatchFinder.cpp +++ lib/ASTMatchers/ASTMatchFinder.cpp @@ -676,13 +676,17 @@ // 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) {
Index: lib/ASTMatchers/ASTMatchFinder.cpp =================================================================== --- lib/ASTMatchers/ASTMatchFinder.cpp +++ lib/ASTMatchers/ASTMatchFinder.cpp @@ -676,13 +676,17 @@ // 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) {
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits