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 | f4381fddf152a63e1ac97185293c47ec0ac2f1a6 (patch) | |
tree | d801ed4df75b9c65dfa1899a94955e5a211d68a5 /Driver/clang.cpp | |
parent | 91d1a14be8eabe235fcf27b070bc9c568d5e1e63 (diff) |
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
Diffstat (limited to 'Driver/clang.cpp')
-rw-r--r-- | Driver/clang.cpp | 39 |
1 files changed, 25 insertions, 14 deletions
diff --git a/Driver/clang.cpp b/Driver/clang.cpp index c1d4707c5d..eddaca3a88 100644 --- a/Driver/clang.cpp +++ b/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) { |