================ @@ -339,6 +339,35 @@ class ClangTidyASTConsumer : public MultiplexConsumer { void anchor() override {}; }; +/// ASTConsumer that filters top-level declarations that are in system headers, +/// and sets the AST traversal scope to only cover the declarations in user +/// headers. This makes all clang-tidy checks avoid spending time processing +/// declarations in system headers. The results are discarded anyway when +/// presenting the results. +class IgnoreSystemHeadersConsumer : public ASTConsumer { +public: + bool HandleTopLevelDecl(DeclGroupRef DG) override { + for (Decl *D : DG) { + if (!isInSystemHeader(D)) + Decls.push_back(D); + } + return true; + } + + void HandleTranslationUnit(ASTContext &Ctx) override { + Ctx.setTraversalScope(Decls); + } + +private: + std::vector<Decl *> Decls; + + bool isInSystemHeader(Decl *D) { + SourceManager &SM = D->getASTContext().getSourceManager(); ---------------- EugeneZelenko wrote:
Should be `const`. Same below. https://github.com/llvm/llvm-project/pull/128150 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits