]> granicus.if.org Git - clang/commitdiff
Make AnalyzerOptions a shared object between CompilerInvocation and
authorTed Kremenek <kremenek@apple.com>
Fri, 31 Aug 2012 04:36:05 +0000 (04:36 +0000)
committerTed Kremenek <kremenek@apple.com>
Fri, 31 Aug 2012 04:36:05 +0000 (04:36 +0000)
AnalysisManager, allowing the StringMap of configuration values to
be propagated.

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

include/clang/Frontend/CompilerInstance.h
include/clang/Frontend/CompilerInvocation.h
include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
lib/Frontend/CompilerInvocation.cpp
lib/FrontendTool/ExecuteCompilerInvocation.cpp
lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
lib/StaticAnalyzer/Frontend/AnalysisConsumer.h

index b28e1031b8358718776f2d452af965a356b482f3..8f1d590686be9a7c4a79b3721f8a9d1cedb62bc1 100644 (file)
@@ -189,10 +189,7 @@ public:
   /// @name Forwarding Methods
   /// {
 
-  AnalyzerOptions &getAnalyzerOpts() {
-    return Invocation->getAnalyzerOpts();
-  }
-  const AnalyzerOptions &getAnalyzerOpts() const {
+  AnalyzerOptionsRef getAnalyzerOpts() {
     return Invocation->getAnalyzerOpts();
   }
 
index d461befdb7c2b31521dcbbdb9d95aecc28f53eef..30c96cbb3393dbffd170330e1a869b8453b8d69e 100644 (file)
@@ -68,7 +68,7 @@ public:
 /// options, the warning flags, and so on.
 class CompilerInvocation : public CompilerInvocationBase {
   /// Options controlling the static analyzer.
-  AnalyzerOptions AnalyzerOpts;
+  AnalyzerOptionsRef AnalyzerOpts;
 
   MigratorOptions MigratorOpts;
   
@@ -100,7 +100,7 @@ class CompilerInvocation : public CompilerInvocationBase {
   TargetOptions TargetOpts;
 
 public:
-  CompilerInvocation() {}
+  CompilerInvocation() : AnalyzerOpts(new AnalyzerOptions()) {}
 
   /// @name Utility Methods
   /// @{
@@ -148,8 +148,7 @@ public:
   /// @name Option Subgroups
   /// @{
 
-  AnalyzerOptions &getAnalyzerOpts() { return AnalyzerOpts; }
-  const AnalyzerOptions &getAnalyzerOpts() const {
+  AnalyzerOptionsRef getAnalyzerOpts() const {
     return AnalyzerOpts;
   }
 
index 99b1c7b0c40982daad8354e31369cded89e33434..d126453c313548403aa6352b48b6f9e229fcb572 100644 (file)
@@ -18,6 +18,7 @@
 #include <string>
 #include <vector>
 #include "llvm/ADT/StringMap.h"
+#include "llvm/ADT/IntrusiveRefCntPtr.h"
 
 namespace clang {
 class ASTConsumer;
@@ -75,7 +76,7 @@ enum AnalysisInliningMode {
 NumInliningModes
 };
 
-class AnalyzerOptions {
+class AnalyzerOptions : public llvm::RefCountedBase<AnalyzerOptions> {
 public:
   typedef llvm::StringMap<std::string> ConfigTable;
 
@@ -164,7 +165,9 @@ public:
     InliningMode = NoRedundancy;
   }
 };
-
+  
+typedef llvm::IntrusiveRefCntPtr<AnalyzerOptions> AnalyzerOptionsRef;
+  
 }
 
 #endif
index 830ab99548ab82098af1239030615e90e775152f..6bffa1346ac731725930be04fbe0aea0fccfc210 100644 (file)
@@ -931,7 +931,7 @@ static void TargetOptsToArgs(const TargetOptions &Opts,
 
 void CompilerInvocation::toArgs(std::vector<std::string> &Res) const {
   ToArgsList List(Res);
-  AnalyzerOptsToArgs(getAnalyzerOpts(), List);
+  AnalyzerOptsToArgs(*getAnalyzerOpts(), List);
   CodeGenOptsToArgs(getCodeGenOpts(), List);
   DependencyOutputOptsToArgs(getDependencyOutputOpts(), List);
   DiagnosticOptsToArgs(getDiagnosticOpts(), List);
@@ -2323,7 +2323,7 @@ bool CompilerInvocation::CreateFromArgs(CompilerInvocation &Res,
     }
   }
 
-  Success = ParseAnalyzerArgs(Res.getAnalyzerOpts(), *Args, Diags) && Success;
+  Success = ParseAnalyzerArgs(*Res.getAnalyzerOpts(), *Args, Diags) && Success;
   Success = ParseMigratorArgs(Res.getMigratorOpts(), *Args) && Success;
   ParseDependencyOutputArgs(Res.getDependencyOutputOpts(), *Args);
   Success = ParseDiagnosticArgs(Res.getDiagnosticOpts(), *Args, &Diags)
index bd50083bf1c999d6c35caa768ecf62df0c275202..31eaccc5b4e4a70b05d565dcd3bf5ed2f4ed1047 100644 (file)
@@ -175,7 +175,7 @@ bool clang::ExecuteCompilerInvocation(CompilerInstance *Clang) {
 
   // Honor -analyzer-checker-help.
   // This should happen AFTER plugins have been loaded!
-  if (Clang->getAnalyzerOpts().ShowCheckerHelp) {
+  if (Clang->getAnalyzerOpts()->ShowCheckerHelp) {
     ento::printCheckerHelp(llvm::outs(), Clang->getFrontendOpts().Plugins);
     return 0;
   }
index 55dd3fa2e302ac4dfdd6ad6b7d43db596a070a36..ac70349a573644d36bbfc0606002c1ff0349ef64 100644 (file)
@@ -135,7 +135,7 @@ public:
   ASTContext *Ctx;
   const Preprocessor &PP;
   const std::string OutDir;
-  AnalyzerOptions Opts;
+  AnalyzerOptionsRef Opts;
   ArrayRef<std::string> Plugins;
 
   /// \brief Stores the declarations from the local translation unit.
@@ -163,19 +163,19 @@ public:
 
   AnalysisConsumer(const Preprocessor& pp,
                    const std::string& outdir,
-                   const AnalyzerOptions& opts,
+                   AnalyzerOptionsRef opts,
                    ArrayRef<std::string> plugins)
     : RecVisitorMode(ANALYSIS_ALL), RecVisitorBR(0),
       Ctx(0), PP(pp), OutDir(outdir), Opts(opts), Plugins(plugins) {
     DigestAnalyzerOptions();
-    if (Opts.PrintStats) {
+    if (Opts->PrintStats) {
       llvm::EnableStatistics();
       TUTotalTimer = new llvm::Timer("Analyzer Total Time");
     }
   }
 
   ~AnalysisConsumer() {
-    if (Opts.PrintStats)
+    if (Opts->PrintStats)
       delete TUTotalTimer;
   }
 
@@ -184,20 +184,20 @@ public:
     PathConsumers.push_back(new ClangDiagPathDiagConsumer(PP.getDiagnostics()));
 
     if (!OutDir.empty()) {
-      switch (Opts.AnalysisDiagOpt) {
+      switch (Opts->AnalysisDiagOpt) {
       default:
 #define ANALYSIS_DIAGNOSTICS(NAME, CMDFLAG, DESC, CREATEFN, AUTOCREATE) \
         case PD_##NAME: CREATEFN(PathConsumers, OutDir, PP); break;
 #include "clang/StaticAnalyzer/Core/Analyses.def"
       }
-    } else if (Opts.AnalysisDiagOpt == PD_TEXT) {
+    } else if (Opts->AnalysisDiagOpt == PD_TEXT) {
       // Create the text client even without a specified output file since
       // it just uses diagnostic notes.
       createTextPathDiagnosticConsumer(PathConsumers, "", PP);
     }
 
     // Create the analyzer component creators.
-    switch (Opts.AnalysisStoreOpt) {
+    switch (Opts->AnalysisStoreOpt) {
     default:
       llvm_unreachable("Unknown store manager.");
 #define ANALYSIS_STORE(NAME, CMDFLAG, DESC, CREATEFN)           \
@@ -205,7 +205,7 @@ public:
 #include "clang/StaticAnalyzer/Core/Analyses.def"
     }
 
-    switch (Opts.AnalysisConstraintsOpt) {
+    switch (Opts->AnalysisConstraintsOpt) {
     default:
       llvm_unreachable("Unknown store manager.");
 #define ANALYSIS_CONSTRAINTS(NAME, CMDFLAG, DESC, CREATEFN)     \
@@ -215,7 +215,7 @@ public:
   }
 
   void DisplayFunction(const Decl *D, AnalysisMode Mode) {
-    if (!Opts.AnalyzerDisplayProgress)
+    if (!Opts->AnalyzerDisplayProgress)
       return;
 
     SourceManager &SM = Mgr->getASTContext().getSourceManager();
@@ -245,7 +245,7 @@ public:
 
   virtual void Initialize(ASTContext &Context) {
     Ctx = &Context;
-    checkerMgr.reset(createCheckerManager(Opts, PP.getLangOpts(), Plugins,
+    checkerMgr.reset(createCheckerManager(*Opts, PP.getLangOpts(), Plugins,
                                           PP.getDiagnostics()));
     Mgr.reset(new AnalysisManager(*Ctx,
                                   PP.getDiagnostics(),
@@ -254,7 +254,7 @@ public:
                                   CreateStoreMgr,
                                   CreateConstraintMgr,
                                   checkerMgr.get(),
-                                  Opts));
+                                  *Opts));
   }
 
   /// \brief Store the top level decls in the set to be processed later on.
@@ -519,15 +519,15 @@ static std::string getFunctionName(const Decl *D) {
 }
 
 bool AnalysisConsumer::skipFunction(Decl *D) {
-  if (!Opts.AnalyzeSpecificFunction.empty() &&
-      getFunctionName(D) != Opts.AnalyzeSpecificFunction)
+  if (!Opts->AnalyzeSpecificFunction.empty() &&
+      getFunctionName(D) != Opts->AnalyzeSpecificFunction)
     return true;
 
   // Don't run the actions on declarations in header files unless
   // otherwise specified.
   SourceManager &SM = Ctx->getSourceManager();
   SourceLocation SL = SM.getExpansionLoc(D->getLocation());
-  if (!Opts.AnalyzeAll && !SM.isFromMainFile(SL))
+  if (!Opts->AnalyzeAll && !SM.isFromMainFile(SL))
     return true;
 
   return false;
@@ -553,7 +553,7 @@ void AnalysisConsumer::HandleCode(Decl *D, AnalysisMode Mode,
   SmallVector<Decl*, 10> WL;
   WL.push_back(D);
 
-  if (D->hasBody() && Opts.AnalyzeNestedBlocks)
+  if (D->hasBody() && Opts->AnalyzeNestedBlocks)
     FindBlocks(cast<DeclContext>(D), WL);
 
   BugReporter BR(*Mgr);
@@ -634,7 +634,7 @@ void AnalysisConsumer::RunPathSensitiveChecks(Decl *D,
 
 ASTConsumer* ento::CreateAnalysisConsumer(const Preprocessor& pp,
                                           const std::string& outDir,
-                                          const AnalyzerOptions& opts,
+                                          AnalyzerOptionsRef opts,
                                           ArrayRef<std::string> plugins) {
   // Disable the effects of '-Werror' when using the AnalysisConsumer.
   pp.getDiagnostics().setWarningsAsErrors(false);
index 5a16bffeacf306d5da0195519562129be8496375..b75220b62de381a34579608b52b183528f0d8703 100644 (file)
 #define LLVM_CLANG_GR_ANALYSISCONSUMER_H
 
 #include "clang/Basic/LLVM.h"
+#include "clang/StaticAnalyzer/Core/AnalyzerOptions.h"
 #include <string>
 
 namespace clang {
 
-class AnalyzerOptions;
 class ASTConsumer;
 class Preprocessor;
 class DiagnosticsEngine;
@@ -33,7 +33,7 @@ class CheckerManager;
 /// options.)
 ASTConsumer* CreateAnalysisConsumer(const Preprocessor &pp,
                                     const std::string &output,
-                                    const AnalyzerOptions& opts,
+                                    AnalyzerOptionsRef opts,
                                     ArrayRef<std::string> plugins);
 
 } // end GR namespace