Added AnalysisConsumer, a meta-level ASTConsumer class to drive various
analyses. This potentially is the primordial origins of a Clang-equivalent
"PassManager".

The new AnalysisConsumer interface allows multiple analyses to be run from a
single invocation of Clang.

Migrated the logic of "-warn-dead-stores" and "-warn-uninit-values" to use the
new AnalysisConsumer interface. The new interface results in a significant code
reduction to incorporate an analysis into the Driver.

Updated a test case to (correctly) acknowledge that it contains a dead store
(this check wasn't being performed because it was previously masked by
-warn-uninit-values).


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@52996 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/Driver/clang.cpp b/Driver/clang.cpp
index c1d4707..eddaca3 100644
--- a/Driver/clang.cpp
+++ b/Driver/clang.cpp
@@ -78,16 +78,14 @@
   AnalysisGRSimpleVals,         // Perform graph-reachability constant prop.
   AnalysisGRSimpleValsView,     // Visualize results of path-sens. analysis.
   CheckerCFRef,                 // Run the Core Foundation Ref. Count Checker.
-  WarnDeadStores,               // Run DeadStores checker on parsed ASTs.
-  WarnDeadStoresCheck,          // Check diagnostics for "DeadStores".
-  WarnUninitVals,               // Run UnitializedVariables checker.
   TestSerialization,            // Run experimental serialization code.
   ParsePrintCallbacks,          // Parse and print each callback.
   ParseSyntaxOnly,              // Parse and perform semantic analysis.
   ParseNoop,                    // Parse with noop callbacks.
   RunPreprocessorOnly,          // Just lex, no output.
   PrintPreprocessedInput,       // -E mode.
-  DumpTokens                    // Token dump mode.
+  DumpTokens,                   // Token dump mode.
+  RunAnalysis                   // Run one or more source code analyses. 
 };
 
 static llvm::cl::opt<ProgActions> 
@@ -120,10 +118,6 @@
                         "Run parser, then build and view CFGs with Graphviz"),
              clEnumValN(AnalysisLiveVariables, "dump-live-variables",
                         "Print results of live variable analysis"),
-             clEnumValN(WarnDeadStores, "warn-dead-stores",
-                        "Flag warnings of stores to dead variables"),
-             clEnumValN(WarnUninitVals, "warn-uninit-values",
-                        "Flag warnings of uses of unitialized variables"),
              clEnumValN(AnalysisGRSimpleVals, "checker-simple",
                         "Perform path-sensitive constant propagation"),
              clEnumValN(CheckerCFRef, "checker-cfref",
@@ -181,6 +175,15 @@
     llvm::cl::desc("Force the static analyzer to analyze "
                    "functions defined in header files"));
 
+static llvm::cl::list<Analyses>
+AnalysisList(llvm::cl::desc("Available Source Code Analyses:"),
+llvm::cl::values(
+clEnumValN(WarnDeadStores, "warn-dead-stores",
+           "Flag warnings of stores to dead variables"),
+clEnumValN(WarnUninitVals, "warn-uninit-values",
+           "Flag warnings of uses of unitialized variables"),
+clEnumValEnd));          
+
 //===----------------------------------------------------------------------===//
 // Language Options
 //===----------------------------------------------------------------------===//
@@ -1199,12 +1202,6 @@
     case AnalysisLiveVariables:
       return CreateLiveVarAnalyzer(AnalyzeSpecificFunction);
       
-    case WarnDeadStores:    
-      return CreateDeadStoreChecker(Diag);
-      
-    case WarnUninitVals:
-      return CreateUnitValsChecker(Diag);
-      
     case AnalysisGRSimpleVals:
       return CreateGRSimpleVals(Diag, PP, PPF, AnalyzeSpecificFunction,
                                 OutputFile, VisualizeEG, TrimGraph, AnalyzeAll);
@@ -1228,6 +1225,15 @@
       
     case RewriteObjC:
       return CreateCodeRewriterTest(InFile, OutputFile, Diag, LangOpts);
+      
+    case RunAnalysis:
+      assert (!AnalysisList.empty());
+      return CreateAnalysisConsumer(&AnalysisList[0],
+                                    &AnalysisList[0]+AnalysisList.size(),
+                                    Diag, PP, PPF, LangOpts,
+                                    AnalyzeSpecificFunction,
+                                    OutputFile, VisualizeEG, TrimGraph,
+                                    AnalyzeAll);
   }
 }
 
@@ -1485,6 +1491,11 @@
     exit(1);
   }
   
+  // Are we invoking one or more source analyses?
+  if (!AnalysisList.empty() && ProgAction == ParseSyntaxOnly)
+    ProgAction = RunAnalysis;  
+  
+  
   llvm::OwningPtr<SourceManager> SourceMgr;
   
   for (unsigned i = 0, e = InputFilenames.size(); i != e; ++i) {