]> granicus.if.org Git - clang/commitdiff
[analyzer] Add ASTContext to CheckerManager
authorGeorge Karpenkov <ekarpenkov@apple.com>
Mon, 6 Aug 2018 23:09:07 +0000 (23:09 +0000)
committerGeorge Karpenkov <ekarpenkov@apple.com>
Mon, 6 Aug 2018 23:09:07 +0000 (23:09 +0000)
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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@339079 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/StaticAnalyzer/Core/CheckerManager.h
include/clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h
include/clang/StaticAnalyzer/Frontend/CheckerRegistration.h
lib/StaticAnalyzer/Core/AnalysisManager.cpp
lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp

index ea2952b3b1149d87f90a502ff87a0ef213e5e30c..463c842ec5b7ac05817e8e700528a1e46e72b471 100644 (file)
@@ -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 *;
index 85369509efcd582544cb127a34e86d72cb85da68..eb91f4b28b98fca0ed8a4db999efcfeed5ad2fe3 100644 (file)
@@ -46,14 +46,12 @@ class AnalysisManager : public BugReporterData {
 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;
 
index 216a2359efba1c15276a7969e88d9a0095fb8313..61709548aed1e82c18f42adb9c1e617214c0ea35 100644 (file)
@@ -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);
index dc0d3ec8493a2998e103a4927eaa64af06443c33..5f45d26d1e85a9fee4373a36e4706c60223e8f5c 100644 (file)
@@ -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();
 }
 
index 44abde5da6d11d56667e247295b71e1ab3318409..20b5223929d1fbb702429f929958876d7243e578 100644 (file)
@@ -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.
index a260c2d85b11f4ea2c1debed94963cb4b405f74a..76e66cc0230c7a09e5039b73a6e03e87587720ef 100644 (file)
@@ -112,12 +112,12 @@ getCheckerOptList(const AnalyzerOptions &opts) {
 }
 
 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);