aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
diff options
context:
space:
mode:
authorBalazs Benics <benicsbalazs@gmail.com>2025-02-22 10:52:31 +0100
committerGitHub <noreply@github.com>2025-02-22 10:52:31 +0100
commitf0088ee87cecfb442921251b4a70f96cf3474a15 (patch)
tree3280c8d162612a900bfce1108aa573ba0832c1bd /clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
parentf4e8f6da41a5ca3e03808d86bce0bcde339b9414 (diff)
downloadllvm-f0088ee87cecfb442921251b4a70f96cf3474a15.zip
llvm-f0088ee87cecfb442921251b4a70f96cf3474a15.tar.gz
llvm-f0088ee87cecfb442921251b4a70f96cf3474a15.tar.bz2
[analyzer] Delay the checker constructions after parsing (#127409)
If we were to delay checker constructions after we have a filled ASTContext, then we could get rid of a bunch of "lazy initializers" in checkers. Turns out in the register functions of the checkers we could transfer the ASTContext and all other things to checkers, so those could benefit from in-class initializers and const fields. For example, if a checker would take the ASTContext as the first field, then the rest of the fields could use it in their in-class initializers, so the ctor of the checker would only need to set a single field! This would open uup countless opportunities for cleaning up the asthetics of our checkers. I attached a single use-case for the AST and the PP as demonstrating purposes. You can imagine the rest. **FYI: This may be a breaking change** to some downstream users that may had some means to attach different listeners and what not to e.g. the Preprocessor inside their checker register functions. Since we delay the calls to these register fns after parsing is already done, they would of course miss the parsing Preprocessor events.
Diffstat (limited to 'clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp')
-rw-r--r--clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp18
1 files changed, 8 insertions, 10 deletions
diff --git a/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp b/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
index 189d7d6..db177b5 100644
--- a/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
+++ b/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
@@ -224,16 +224,6 @@ public:
}
}
- void Initialize(ASTContext &Context) override {
- Ctx = &Context;
- checkerMgr = std::make_unique<CheckerManager>(*Ctx, Opts, PP, Plugins,
- CheckerRegistrationFns);
-
- Mgr = std::make_unique<AnalysisManager>(*Ctx, PP, PathConsumers,
- CreateStoreMgr, CreateConstraintMgr,
- checkerMgr.get(), Opts, Injector);
- }
-
/// Store the top level decls in the set to be processed later on.
/// (Doing this pre-processing avoids deserialization of data from PCH.)
bool HandleTopLevelDecl(DeclGroupRef D) override;
@@ -615,6 +605,14 @@ void AnalysisConsumer::HandleTranslationUnit(ASTContext &C) {
if (Diags.hasErrorOccurred() || Diags.hasFatalErrorOccurred())
return;
+ Ctx = &C;
+ checkerMgr = std::make_unique<CheckerManager>(*Ctx, Opts, PP, Plugins,
+ CheckerRegistrationFns);
+
+ Mgr = std::make_unique<AnalysisManager>(*Ctx, PP, PathConsumers,
+ CreateStoreMgr, CreateConstraintMgr,
+ checkerMgr.get(), Opts, Injector);
+
// Explicitly destroy the PathDiagnosticConsumer. This will flush its output.
// FIXME: This should be replaced with something that doesn't rely on
// side-effects in PathDiagnosticConsumer's destructor. This is required when