diff options
| author | Ted Kremenek <kremenek@apple.com> | 2008-07-02 00:03:09 +0000 |
|---|---|---|
| committer | Ted Kremenek <kremenek@apple.com> | 2008-07-02 00:03:09 +0000 |
| commit | f0413bfcda2e8498b6381fe4be8589f5b157ce0f (patch) | |
| tree | 7d1e818106f1d86077b7ac71e8caf02c6440f50b /clang/Driver/clang.cpp | |
| parent | 31936d6ab639762ff488a94e1daad2b235b65607 (diff) | |
| download | bcm5719-llvm-f0413bfcda2e8498b6381fe4be8589f5b157ce0f.tar.gz bcm5719-llvm-f0413bfcda2e8498b6381fe4be8589f5b157ce0f.zip | |
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).
llvm-svn: 52996
Diffstat (limited to 'clang/Driver/clang.cpp')
| -rw-r--r-- | clang/Driver/clang.cpp | 39 |
1 files changed, 25 insertions, 14 deletions
diff --git a/clang/Driver/clang.cpp b/clang/Driver/clang.cpp index c1d4707c5de..eddaca3a88d 100644 --- a/clang/Driver/clang.cpp +++ b/clang/Driver/clang.cpp @@ -78,16 +78,14 @@ enum ProgActions { 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 @@ ProgAction(llvm::cl::desc("Choose output type:"), llvm::cl::ZeroOrMore, "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 @@ AnalyzeAll("checker-opt-analyze-headers", 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 @@ static ASTConsumer* CreateASTConsumer(const std::string& InFile, 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 @@ static ASTConsumer* CreateASTConsumer(const std::string& InFile, 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 @@ int main(int argc, char **argv) { 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) { |

