[clang-tools-extra] [clang-tidy] Avoid processing declarations in system headers (PR #128150)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Feb 21 07:35:08 PST 2025
================
@@ -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;
----------------
EugeneZelenko wrote:
Please include `vector`.
https://github.com/llvm/llvm-project/pull/128150
More information about the cfe-commits
mailing list