Index: clang-tidy/misc/UnusedParametersCheck.cpp =================================================================== --- clang-tidy/misc/UnusedParametersCheck.cpp +++ clang-tidy/misc/UnusedParametersCheck.cpp @@ -74,7 +74,7 @@ class UnusedParametersCheck::IndexerVisitor : public RecursiveASTVisitor { public: - IndexerVisitor(TranslationUnitDecl *Top) { TraverseDecl(Top); } + IndexerVisitor(ASTContext &Ctx) { TraverseAST(Ctx); } const std::unordered_set & getFnCalls(const FunctionDecl *Fn) { @@ -136,8 +136,7 @@ auto MyDiag = diag(Param->getLocation(), "parameter %0 is unused") << Param; if (!Indexer) { - Indexer = llvm::make_unique( - Result.Context->getTranslationUnitDecl()); + Indexer = llvm::make_unique(*Result.Context); } // Comment out parameter name for non-local functions. Index: clang-tidy/modernize/LoopConvertCheck.cpp =================================================================== --- clang-tidy/modernize/LoopConvertCheck.cpp +++ clang-tidy/modernize/LoopConvertCheck.cpp @@ -899,7 +899,7 @@ // variable declared inside the loop outside of it. // FIXME: Determine when the external dependency isn't an expression converted // by another loop. - TUInfo->getParentFinder().gatherAncestors(Context->getTranslationUnitDecl()); + TUInfo->getParentFinder().gatherAncestors(*Context); DependencyFinderASTVisitor DependencyFinder( &TUInfo->getParentFinder().getStmtToParentStmtMap(), &TUInfo->getParentFinder().getDeclToParentStmtMap(), Index: clang-tidy/modernize/LoopConvertUtils.h =================================================================== --- clang-tidy/modernize/LoopConvertUtils.h +++ clang-tidy/modernize/LoopConvertUtils.h @@ -56,12 +56,12 @@ public: StmtAncestorASTVisitor() { StmtStack.push_back(nullptr); } - /// \brief Run the analysis on the TranslationUnitDecl. + /// \brief Run the analysis on the AST. /// /// In case we're running this analysis multiple times, don't repeat the work. - void gatherAncestors(const clang::TranslationUnitDecl *T) { + void gatherAncestors(ASTContext &Ctx) { if (StmtAncestors.empty()) - TraverseDecl(const_cast(T)); + TraverseAST(Ctx); } /// Accessor for StmtAncestors. Index: clang-tidy/readability/SimplifyBooleanExprCheck.h =================================================================== --- clang-tidy/readability/SimplifyBooleanExprCheck.h +++ clang-tidy/readability/SimplifyBooleanExprCheck.h @@ -79,6 +79,7 @@ SourceLocation Loc, StringRef Description, SourceRange ReplacementRange, StringRef Replacement); + bool MatchedOnce = false; const bool ChainedConditionalReturn; const bool ChainedConditionalAssignment; }; Index: clang-tidy/readability/SimplifyBooleanExprCheck.cpp =================================================================== --- clang-tidy/readability/SimplifyBooleanExprCheck.cpp +++ clang-tidy/readability/SimplifyBooleanExprCheck.cpp @@ -507,8 +507,16 @@ ChainedConditionalAssignment); } +// This is a silly hack to let us run a RecursiveASTVisitor on the Context. +// We want to match exactly one node in the AST, doesn't matter which. +AST_MATCHER_P(Decl, matchOnce, bool *, Matched) { + if (*Matched) + return false; + return *Matched = true; +} + void SimplifyBooleanExprCheck::registerMatchers(MatchFinder *Finder) { - Finder->addMatcher(translationUnitDecl().bind("top"), this); + Finder->addMatcher(matchOnce(&MatchedOnce), this); matchBoolCondition(Finder, true, ConditionThenStmtId); matchBoolCondition(Finder, false, ConditionElseStmtId); @@ -556,8 +564,8 @@ else if (const auto *Compound = Result.Nodes.getNodeAs(CompoundNotBoolId)) replaceCompoundReturnWithCondition(Result, Compound, true); - else if (const auto TU = Result.Nodes.getNodeAs("top")) - Visitor(this, Result).TraverseDecl(const_cast(TU)); + else // MatchOnce matcher + Visitor(this, Result).TraverseAST(*Result.Context); } void SimplifyBooleanExprCheck::issueDiag(