r339079 - [analyzer] Add ASTContext to CheckerManager
George Karpenkov via cfe-commits
cfe-commits at lists.llvm.org
Mon Aug 6 16:09:08 PDT 2018
Author: george.karpenkov
Date: Mon Aug 6 16:09:07 2018
New Revision: 339079
URL: http://llvm.org/viewvc/llvm-project?rev=339079&view=rev
Log:
[analyzer] Add ASTContext to CheckerManager
Some checkers require ASTContext. Having it in the constructor saves a
lot of boilerplate of having to pass it around.
Differential Revision: https://reviews.llvm.org/D50111
Modified:
cfe/trunk/include/clang/StaticAnalyzer/Core/CheckerManager.h
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h
cfe/trunk/include/clang/StaticAnalyzer/Frontend/CheckerRegistration.h
cfe/trunk/lib/StaticAnalyzer/Core/AnalysisManager.cpp
cfe/trunk/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
cfe/trunk/lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp
Modified: cfe/trunk/include/clang/StaticAnalyzer/Core/CheckerManager.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/CheckerManager.h?rev=339079&r1=339078&r2=339079&view=diff
==============================================================================
--- cfe/trunk/include/clang/StaticAnalyzer/Core/CheckerManager.h (original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/CheckerManager.h Mon Aug 6 16:09:07 2018
@@ -115,13 +115,14 @@ enum class ObjCMessageVisitKind {
};
class CheckerManager {
+ ASTContext &Context;
const LangOptions LangOpts;
AnalyzerOptions &AOptions;
CheckName CurrentCheckName;
public:
- CheckerManager(const LangOptions &langOpts, AnalyzerOptions &AOptions)
- : LangOpts(langOpts), AOptions(AOptions) {}
+ CheckerManager(ASTContext &Context, AnalyzerOptions &AOptions)
+ : Context(Context), LangOpts(Context.getLangOpts()), AOptions(AOptions) {}
~CheckerManager();
@@ -134,6 +135,7 @@ public:
const LangOptions &getLangOpts() const { return LangOpts; }
AnalyzerOptions &getAnalyzerOptions() { return AOptions; }
+ ASTContext &getASTContext() { return Context; }
using CheckerRef = CheckerBase *;
using CheckerTag = const void *;
Modified: cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h?rev=339079&r1=339078&r2=339079&view=diff
==============================================================================
--- cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h (original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h Mon Aug 6 16:09:07 2018
@@ -46,14 +46,12 @@ class AnalysisManager : public BugReport
public:
AnalyzerOptions &options;
- AnalysisManager(ASTContext &ctx,DiagnosticsEngine &diags,
- const LangOptions &lang,
+ AnalysisManager(ASTContext &ctx, DiagnosticsEngine &diags,
const PathDiagnosticConsumers &Consumers,
StoreManagerCreator storemgr,
ConstraintManagerCreator constraintmgr,
- CheckerManager *checkerMgr,
- AnalyzerOptions &Options,
- CodeInjector* injector = nullptr);
+ CheckerManager *checkerMgr, AnalyzerOptions &Options,
+ CodeInjector *injector = nullptr);
~AnalysisManager() override;
Modified: cfe/trunk/include/clang/StaticAnalyzer/Frontend/CheckerRegistration.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Frontend/CheckerRegistration.h?rev=339079&r1=339078&r2=339079&view=diff
==============================================================================
--- cfe/trunk/include/clang/StaticAnalyzer/Frontend/CheckerRegistration.h (original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Frontend/CheckerRegistration.h Mon Aug 6 16:09:07 2018
@@ -10,6 +10,7 @@
#ifndef LLVM_CLANG_STATICANALYZER_FRONTEND_CHECKERREGISTRATION_H
#define LLVM_CLANG_STATICANALYZER_FRONTEND_CHECKERREGISTRATION_H
+#include "clang/AST/ASTContext.h"
#include "clang/Basic/LLVM.h"
#include <functional>
#include <memory>
@@ -25,7 +26,8 @@ namespace ento {
class CheckerRegistry;
std::unique_ptr<CheckerManager> createCheckerManager(
- AnalyzerOptions &opts, const LangOptions &langOpts,
+ ASTContext &context,
+ AnalyzerOptions &opts,
ArrayRef<std::string> plugins,
ArrayRef<std::function<void(CheckerRegistry &)>> checkerRegistrationFns,
DiagnosticsEngine &diags);
Modified: cfe/trunk/lib/StaticAnalyzer/Core/AnalysisManager.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/AnalysisManager.cpp?rev=339079&r1=339078&r2=339079&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/AnalysisManager.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/AnalysisManager.cpp Mon Aug 6 16:09:07 2018
@@ -14,28 +14,28 @@ using namespace ento;
void AnalysisManager::anchor() { }
-AnalysisManager::AnalysisManager(
- ASTContext &ASTCtx, DiagnosticsEngine &diags, const LangOptions &lang,
- const PathDiagnosticConsumers &PDC, StoreManagerCreator storemgr,
- ConstraintManagerCreator constraintmgr, CheckerManager *checkerMgr,
- AnalyzerOptions &Options, CodeInjector *injector)
- : AnaCtxMgr(ASTCtx, Options.UnoptimizedCFG,
- Options.includeImplicitDtorsInCFG(),
- /*AddInitializers=*/true, Options.includeTemporaryDtorsInCFG(),
- Options.includeLifetimeInCFG(),
- // Adding LoopExit elements to the CFG is a requirement for loop
- // unrolling.
- Options.includeLoopExitInCFG() || Options.shouldUnrollLoops(),
- Options.includeScopesInCFG(),
- Options.shouldSynthesizeBodies(),
- Options.shouldConditionalizeStaticInitializers(),
- /*addCXXNewAllocator=*/true,
- Options.includeRichConstructorsInCFG(),
- Options.shouldElideConstructors(),
- injector),
- Ctx(ASTCtx), Diags(diags), LangOpts(lang), PathConsumers(PDC),
- CreateStoreMgr(storemgr), CreateConstraintMgr(constraintmgr),
- CheckerMgr(checkerMgr), options(Options) {
+AnalysisManager::AnalysisManager(ASTContext &ASTCtx, DiagnosticsEngine &diags,
+ const PathDiagnosticConsumers &PDC,
+ StoreManagerCreator storemgr,
+ ConstraintManagerCreator constraintmgr,
+ CheckerManager *checkerMgr,
+ AnalyzerOptions &Options,
+ CodeInjector *injector)
+ : AnaCtxMgr(
+ ASTCtx, Options.UnoptimizedCFG, Options.includeImplicitDtorsInCFG(),
+ /*AddInitializers=*/true, Options.includeTemporaryDtorsInCFG(),
+ Options.includeLifetimeInCFG(),
+ // Adding LoopExit elements to the CFG is a requirement for loop
+ // unrolling.
+ Options.includeLoopExitInCFG() || Options.shouldUnrollLoops(),
+ Options.includeScopesInCFG(), Options.shouldSynthesizeBodies(),
+ Options.shouldConditionalizeStaticInitializers(),
+ /*addCXXNewAllocator=*/true, Options.includeRichConstructorsInCFG(),
+ Options.shouldElideConstructors(), injector),
+ Ctx(ASTCtx), Diags(diags), LangOpts(ASTCtx.getLangOpts()),
+ PathConsumers(PDC), CreateStoreMgr(storemgr),
+ CreateConstraintMgr(constraintmgr), CheckerMgr(checkerMgr),
+ options(Options) {
AnaCtxMgr.getCFGBuildOptions().setAllAlwaysAdd();
}
Modified: cfe/trunk/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp?rev=339079&r1=339078&r2=339079&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp Mon Aug 6 16:09:07 2018
@@ -295,13 +295,12 @@ public:
void Initialize(ASTContext &Context) override {
Ctx = &Context;
- checkerMgr =
- createCheckerManager(*Opts, PP.getLangOpts(), Plugins,
- CheckerRegistrationFns, PP.getDiagnostics());
+ checkerMgr = createCheckerManager(
+ *Ctx, *Opts, Plugins, CheckerRegistrationFns, PP.getDiagnostics());
Mgr = llvm::make_unique<AnalysisManager>(
- *Ctx, PP.getDiagnostics(), PP.getLangOpts(), PathConsumers,
- CreateStoreMgr, CreateConstraintMgr, checkerMgr.get(), *Opts, Injector);
+ *Ctx, PP.getDiagnostics(), PathConsumers, CreateStoreMgr,
+ CreateConstraintMgr, checkerMgr.get(), *Opts, Injector);
}
/// Store the top level decls in the set to be processed later on.
Modified: cfe/trunk/lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp?rev=339079&r1=339078&r2=339079&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp Mon Aug 6 16:09:07 2018
@@ -112,12 +112,12 @@ getCheckerOptList(const AnalyzerOptions
}
std::unique_ptr<CheckerManager> ento::createCheckerManager(
- AnalyzerOptions &opts, const LangOptions &langOpts,
+ ASTContext &context,
+ AnalyzerOptions &opts,
ArrayRef<std::string> plugins,
ArrayRef<std::function<void(CheckerRegistry &)>> checkerRegistrationFns,
DiagnosticsEngine &diags) {
- std::unique_ptr<CheckerManager> checkerMgr(
- new CheckerManager(langOpts, opts));
+ auto checkerMgr = llvm::make_unique<CheckerManager>(context, opts);
SmallVector<CheckerOptInfo, 8> checkerOpts = getCheckerOptList(opts);
More information about the cfe-commits
mailing list