]> granicus.if.org Git - clang/commitdiff
Add -cc1 option '-unoptimized-cfg' to toggle using a CFG (for static analysis) that...
authorTed Kremenek <kremenek@apple.com>
Tue, 3 Aug 2010 00:09:51 +0000 (00:09 +0000)
committerTed Kremenek <kremenek@apple.com>
Tue, 3 Aug 2010 00:09:51 +0000 (00:09 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@110087 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Analysis/AnalysisContext.h
include/clang/Checker/PathSensitive/AnalysisManager.h
include/clang/Driver/CC1Options.td
include/clang/Frontend/AnalyzerOptions.h
lib/Analysis/AnalysisContext.cpp
lib/Checker/AnalysisConsumer.cpp
lib/Checker/GRCoreEngine.cpp
lib/Frontend/CompilerInvocation.cpp

index 169b1525d6d2066234f4fcc8de4f3101bd7f014f..2b595b99cb7484c30d403f4c6cdb47820bd41665 100644 (file)
@@ -51,14 +51,17 @@ class AnalysisContext {
   ParentMap *PM;
   llvm::DenseMap<const BlockDecl*,void*> *ReferencedBlockVars;
   llvm::BumpPtrAllocator A;
+  bool UseUnoptimizedCFG;  
   bool AddEHEdges;
 public:
   AnalysisContext(const Decl *d, idx::TranslationUnit *tu,
+                  bool useUnoptimizedCFG = false,
                   bool addehedges = false)
     : D(d), TU(tu), cfg(0), completeCFG(0),
       builtCFG(false), builtCompleteCFG(false),
       liveness(0), PM(0),
-      ReferencedBlockVars(0), AddEHEdges(addehedges) {}
+      ReferencedBlockVars(0), UseUnoptimizedCFG(useUnoptimizedCFG),
+      AddEHEdges(addehedges) {}
 
   ~AnalysisContext();
 
@@ -72,6 +75,9 @@ public:
   /// reachable from them can appear to be dead in the CFG, analysis passes must
   /// cope with that.
   bool getAddEHEdges() const { return AddEHEdges; }
+  
+  bool getUseUnoptimizedCFG() const { return UseUnoptimizedCFG; }
+
   Stmt *getBody();
   CFG *getCFG();
   
@@ -94,11 +100,17 @@ public:
 class AnalysisContextManager {
   typedef llvm::DenseMap<const Decl*, AnalysisContext*> ContextMap;
   ContextMap Contexts;
+  bool UseUnoptimizedCFG;
 public:
+  AnalysisContextManager(bool useUnoptimizedCFG = false)
+    : UseUnoptimizedCFG(useUnoptimizedCFG) {}
+  
   ~AnalysisContextManager();
 
   AnalysisContext *getContext(const Decl *D, idx::TranslationUnit *TU = 0);
 
+  bool getUseUnoptimizedCFG() const { return UseUnoptimizedCFG; }
+
   // Discard all previously created AnalysisContexts.
   void clear();
 };
index 606dd0df6ddc458c6d28b746a4edb5dec1f056c9..38550798b812fcbdef73370dabbe6c69686f1cbf 100644 (file)
@@ -76,9 +76,10 @@ public:
                   idx::Indexer *idxer,
                   unsigned maxnodes, unsigned maxloop,
                   bool vizdot, bool vizubi, bool purge, bool eager, bool trim,
-                  bool inlinecall)
+                  bool inlinecall, bool useUnoptimizedCFG)
 
-    : Ctx(ctx), Diags(diags), LangInfo(lang), PD(pd),
+    : AnaCtxMgr(useUnoptimizedCFG), Ctx(ctx), Diags(diags), LangInfo(lang),
+      PD(pd),
       CreateStoreMgr(storemgr), CreateConstraintMgr(constraintmgr),Idxer(idxer),
       AScope(ScopeDecl), MaxNodes(maxnodes), MaxLoop(maxloop),
       VisualizeEGDot(vizdot), VisualizeEGUbi(vizubi), PurgeDead(purge),
@@ -90,6 +91,10 @@ public:
     LocCtxMgr.clear();
     AnaCtxMgr.clear();
   }
+  
+  AnalysisContextManager& getAnalysisContextManager() {
+    return AnaCtxMgr;
+  }
 
   StoreManagerCreator getStoreManagerCreator() {
     return CreateStoreMgr;
index cd4b9f75b0bf2a39c08a0c3b140bc1af98962460..b0ae9b5fbd428e522c3511d56a168d0763b12224 100644 (file)
@@ -38,6 +38,8 @@ def analysis_CFGDump : Flag<"-cfg-dump">,
   HelpText<"Display Control-Flow Graphs">;
 def analysis_CFGView : Flag<"-cfg-view">,
   HelpText<"View Control-Flow Graphs using GraphViz">;
+def analysis_UnoptimizedCFG : Flag<"-unoptimized-cfg">,
+  HelpText<"View Control-Flow Graphs using GraphViz">;
 def analysis_DisplayLiveVariables : Flag<"-dump-live-variables">,
   HelpText<"Print results of live variable analysis">;
 def analysis_LLVMConventionChecker : Flag<"-analyzer-check-llvm-conventions">,
index ab4aed96d864ca495c05248669928c6d0e201133..33cef96c64fbb0036c268f62fd1bf11d03832aef 100644 (file)
@@ -74,6 +74,7 @@ public:
   unsigned EnableExperimentalInternalChecks : 1;
   unsigned EnableIdempotentOperationChecker : 1;
   unsigned InlineCall : 1;
+  unsigned UnoptimizedCFG : 1;
 
 public:
   AnalyzerOptions() {
@@ -90,6 +91,7 @@ public:
     VisualizeEGUbi = 0;
     EnableExperimentalChecks = 0;
     EnableExperimentalInternalChecks = 0;
+    UnoptimizedCFG = 0;
   }
 };
 
index ef0a50f98ee62da7a0d03b1e19597c3fde841e1c..ced4f1dd2eeabf911d8ddce1d4c5d3a6b01f351b 100644 (file)
@@ -54,6 +54,9 @@ const ImplicitParamDecl *AnalysisContext::getSelfDecl() const {
 }
 
 CFG *AnalysisContext::getCFG() {
+  if (UseUnoptimizedCFG)
+    return getUnoptimizedCFG();
+
   if (!builtCFG) {
     cfg = CFG::buildCFG(D, getBody(), &D->getASTContext(), true, AddEHEdges);
     // Even when the cfg is not successfully built, we don't
@@ -98,7 +101,7 @@ AnalysisContext *AnalysisContextManager::getContext(const Decl *D,
                                                     idx::TranslationUnit *TU) {
   AnalysisContext *&AC = Contexts[D];
   if (!AC)
-    AC = new AnalysisContext(D, TU);
+    AC = new AnalysisContext(D, TU, UseUnoptimizedCFG);
 
   return AC;
 }
index bbeca312f093f3e8aac40ad52376f445f1a230cf..2607664406eb656c831241b1624944a042ba53df 100644 (file)
@@ -177,7 +177,8 @@ public:
                                   Opts.MaxNodes, Opts.MaxLoop,
                                   Opts.VisualizeEGDot, Opts.VisualizeEGUbi,
                                   Opts.PurgeDead, Opts.EagerlyAssume,
-                                  Opts.TrimGraph, Opts.InlineCall));
+                                  Opts.TrimGraph, Opts.InlineCall,
+                                  Opts.UnoptimizedCFG));
   }
 
   virtual void HandleTranslationUnit(ASTContext &C);
index b0be7096615d2f2b6c6c9ff094ffce51f35c014c..c2a33225370b545512a19b077797f1990a2b3f5e 100644 (file)
@@ -708,7 +708,8 @@ void GRCallEnterNodeBuilder::GenerateNode(const GRState *state,
                          OldMgr.shouldPurgeDead(),
                          OldMgr.shouldEagerlyAssume(),
                          OldMgr.shouldTrimGraph(),
-                         OldMgr.shouldInlineCall());
+                         OldMgr.shouldInlineCall(),
+                     OldMgr.getAnalysisContextManager().getUseUnoptimizedCFG());
     llvm::OwningPtr<GRTransferFuncs> TF(MakeCFRefCountTF(AMgr.getASTContext(),
                                                          /* GCEnabled */ false,
                                                         AMgr.getLangOptions()));
index 0ae4739b410cefe559351b01d2e7345e1af6328a..6da2319cd88560c50b67b59d3644beecc49a09db 100644 (file)
@@ -786,6 +786,7 @@ static void ParseAnalyzerArgs(AnalyzerOptions &Opts, ArgList &Args,
   Opts.PurgeDead = !Args.hasArg(OPT_analyzer_no_purge_dead);
   Opts.EagerlyAssume = Args.hasArg(OPT_analyzer_eagerly_assume);
   Opts.AnalyzeSpecificFunction = Args.getLastArgValue(OPT_analyze_function);
+  Opts.UnoptimizedCFG = Args.hasArg(OPT_analysis_UnoptimizedCFG);
   Opts.EnableExperimentalChecks = Args.hasArg(OPT_analyzer_experimental_checks);
   Opts.EnableExperimentalInternalChecks =
     Args.hasArg(OPT_analyzer_experimental_internal_checks);