Simplify passing of CFGBuildOptions around for AnalysisContext.  No functionality change.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@135666 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Analysis/AnalysisContext.cpp b/lib/Analysis/AnalysisContext.cpp
index 678f02f..7ee247d 100644
--- a/lib/Analysis/AnalysisContext.cpp
+++ b/lib/Analysis/AnalysisContext.cpp
@@ -24,6 +24,7 @@
 #include "clang/Analysis/CFG.h"
 #include "clang/Analysis/CFGStmtMap.h"
 #include "clang/Analysis/Support/BumpVector.h"
+#include "clang/Analysis/Support/SaveAndRestore.h"
 #include "llvm/ADT/SmallSet.h"
 #include "llvm/Support/ErrorHandling.h"
 
@@ -31,18 +32,32 @@
 
 AnalysisContext::AnalysisContext(const Decl *d,
                                  idx::TranslationUnit *tu,
-                                 bool useUnoptimizedCFG,
-                                 bool addehedges,
-                                 bool addImplicitDtors,
-                                 bool addInitializers)
+                                 const CFG::BuildOptions &buildOptions)
   : D(d), TU(tu),
+    cfgBuildOptions(buildOptions),
     forcedBlkExprs(0),
-    builtCFG(false), builtCompleteCFG(false),
-    useUnoptimizedCFG(useUnoptimizedCFG),
+    builtCFG(false),
+    builtCompleteCFG(false),
     ReferencedBlockVars(0)
-{
+{  
   cfgBuildOptions.forcedBlkExprs = &forcedBlkExprs;
-  cfgBuildOptions.AddEHEdges = addehedges;
+}
+
+AnalysisContext::AnalysisContext(const Decl *d,
+                                 idx::TranslationUnit *tu)
+: D(d), TU(tu),
+  forcedBlkExprs(0),
+  builtCFG(false),
+  builtCompleteCFG(false),
+  ReferencedBlockVars(0)
+{  
+  cfgBuildOptions.forcedBlkExprs = &forcedBlkExprs;
+}
+
+AnalysisContextManager::AnalysisContextManager(bool useUnoptimizedCFG,
+                                               bool addImplicitDtors,
+                                               bool addInitializers) {
+  cfgBuildOptions.PruneTriviallyFalseEdges = !useUnoptimizedCFG;
   cfgBuildOptions.AddImplicitDtors = addImplicitDtors;
   cfgBuildOptions.AddInitializers = addInitializers;
 }
@@ -95,7 +110,7 @@
 }
 
 CFG *AnalysisContext::getCFG() {
-  if (useUnoptimizedCFG)
+  if (!cfgBuildOptions.PruneTriviallyFalseEdges)
     return getUnoptimizedCFG();
 
   if (!builtCFG) {
@@ -110,9 +125,10 @@
 
 CFG *AnalysisContext::getUnoptimizedCFG() {
   if (!builtCompleteCFG) {
-    CFG::BuildOptions B = cfgBuildOptions;
-    B.PruneTriviallyFalseEdges = false;
-    completeCFG.reset(CFG::buildCFG(D, getBody(), &D->getASTContext(), B));
+    SaveAndRestore<bool> NotPrune(cfgBuildOptions.PruneTriviallyFalseEdges,
+                                  false);
+    completeCFG.reset(CFG::buildCFG(D, getBody(), &D->getASTContext(),
+                                    cfgBuildOptions));
     // Even when the cfg is not successfully built, we don't
     // want to try building it again.
     builtCompleteCFG = true;
@@ -187,9 +203,7 @@
                                                     idx::TranslationUnit *TU) {
   AnalysisContext *&AC = Contexts[D];
   if (!AC)
-    AC = new AnalysisContext(D, TU, UseUnoptimizedCFG, false,
-        AddImplicitDtors, AddInitializers);
-
+    AC = new AnalysisContext(D, TU, cfgBuildOptions);
   return AC;
 }
 
diff --git a/lib/Sema/AnalysisBasedWarnings.cpp b/lib/Sema/AnalysisBasedWarnings.cpp
index c0e2715..06e42b7 100644
--- a/lib/Sema/AnalysisBasedWarnings.cpp
+++ b/lib/Sema/AnalysisBasedWarnings.cpp
@@ -656,10 +656,14 @@
   const Stmt *Body = D->getBody();
   assert(Body);
 
+  AnalysisContext AC(D, 0);
+
   // Don't generate EH edges for CallExprs as we'd like to avoid the n^2
   // explosion for destrutors that can result and the compile time hit.
-  AnalysisContext AC(D, 0, /*useUnoptimizedCFG=*/false, /*addehedges=*/false,
-                     /*addImplicitDtors=*/true, /*addInitializers=*/true);
+  AC.getCFGBuildOptions().PruneTriviallyFalseEdges = true;
+  AC.getCFGBuildOptions().AddEHEdges = false;
+  AC.getCFGBuildOptions().AddInitializers = true;
+  AC.getCFGBuildOptions().AddImplicitDtors = true;
   
   // Force that certain expressions appear as CFGElements in the CFG.  This
   // is used to speed up various analyses.
@@ -667,14 +671,16 @@
   // prototyping, but we need a way for analyses to say what expressions they
   // expect to always be CFGElements and then fill in the BuildOptions
   // appropriately.  This is essentially a layering violation.
-  CFG::BuildOptions &buildOptions = AC.getCFGBuildOptions();
-  buildOptions.setAlwaysAdd(Stmt::BinaryOperatorClass);
-  buildOptions.setAlwaysAdd(Stmt::BlockExprClass);
-  buildOptions.setAlwaysAdd(Stmt::CStyleCastExprClass);
-  buildOptions.setAlwaysAdd(Stmt::DeclRefExprClass);
-  buildOptions.setAlwaysAdd(Stmt::ImplicitCastExprClass);
-  buildOptions.setAlwaysAdd(Stmt::UnaryOperatorClass);
+  AC.getCFGBuildOptions()
+    .setAlwaysAdd(Stmt::BinaryOperatorClass)
+    .setAlwaysAdd(Stmt::BlockExprClass)
+    .setAlwaysAdd(Stmt::CStyleCastExprClass)
+    .setAlwaysAdd(Stmt::DeclRefExprClass)
+    .setAlwaysAdd(Stmt::ImplicitCastExprClass)
+    .setAlwaysAdd(Stmt::UnaryOperatorClass);
 
+  // Construct the analysis context with the specified CFG build options.
+  
   // Emit delayed diagnostics.
   if (!fscope->PossiblyUnreachableDiags.empty()) {
     bool analyzed = false;
diff --git a/lib/StaticAnalyzer/Core/CoreEngine.cpp b/lib/StaticAnalyzer/Core/CoreEngine.cpp
index 34cd6e8..9fcc04e 100644
--- a/lib/StaticAnalyzer/Core/CoreEngine.cpp
+++ b/lib/StaticAnalyzer/Core/CoreEngine.cpp
@@ -787,7 +787,7 @@
 
     // Create a new AnalysisManager with components of the callee's
     // TranslationUnit.
-    // The Diagnostic is actually shared when we create ASTUnits from AST files.
+    // The Diagnostic is  actually shared when we create ASTUnits from AST files.
     AnalysisManager AMgr(TU->getASTContext(), TU->getDiagnostic(), 
                          OldMgr.getLangOptions(), 
                          OldMgr.getPathDiagnosticClient(),
@@ -803,8 +803,10 @@
                          OldMgr.shouldTrimGraph(),
                          OldMgr.shouldInlineCall(),
                      OldMgr.getAnalysisContextManager().getUseUnoptimizedCFG(),
-                     OldMgr.getAnalysisContextManager().getAddImplicitDtors(),
-                     OldMgr.getAnalysisContextManager().getAddInitializers(),
+                     OldMgr.getAnalysisContextManager().
+                         getCFGBuildOptions().AddImplicitDtors,
+                     OldMgr.getAnalysisContextManager().
+                         getCFGBuildOptions().AddInitializers,
                      OldMgr.shouldEagerlyTrimExplodedGraph());
     llvm::OwningPtr<TransferFuncs> TF(MakeCFRefCountTF(AMgr.getASTContext(),
                                                          /* GCEnabled */ false,