diff --git a/clang/Driver/DiagChecker.cpp b/clang/Driver/DiagChecker.cpp index 48d804978022..21c3454bfdc4 100644 --- a/clang/Driver/DiagChecker.cpp +++ b/clang/Driver/DiagChecker.cpp @@ -227,17 +227,22 @@ static bool CheckResults(Preprocessor &PP, bool clang::CheckDiagnostics(Preprocessor &PP, unsigned MainFileID) { // Parse the specified input file, building ASTs and performing sema, but // doing nothing else. -{ - ASTConsumer NullConsumer; - ParseAST(PP, MainFileID, NullConsumer); + return CheckASTConsumer(PP,MainFileID, + std::auto_ptr(new ASTConsumer())); } +/// CheckASTConsumer - Implement diagnostic checking for AST consumers. +bool clang::CheckASTConsumer(Preprocessor &PP, unsigned MainFileID, + std::auto_ptr C) { + + // Local scope for ASTConsumer to auto release the consumer ... + { std::auto_ptr Consumer(C); + ParseAST(PP, MainFileID, *Consumer.get()); } + // Gather the set of expected diagnostics. DiagList ExpectedErrors, ExpectedWarnings; FindExpectedDiags(PP, MainFileID, ExpectedErrors, ExpectedWarnings); - + // Check that the expected diagnostics occurred. return CheckResults(PP, ExpectedErrors, ExpectedWarnings); } - - diff --git a/clang/Driver/clang.cpp b/clang/Driver/clang.cpp index 77a568adac8a..6ff5580f2ca1 100644 --- a/clang/Driver/clang.cpp +++ b/clang/Driver/clang.cpp @@ -59,6 +59,7 @@ enum ProgActions { ParseCFGView, // Parse ASTS. Build CFGs. View CFGs. AnalysisLiveVariables, // Print results of live-variable analysis. WarnDeadStores, // Run DeadStores checker on parsed ASTs. + WarnDeadStoresCheck, // Check diagnostics for "DeadStores". WarnUninitVals, // Run UnitializedVariables checker. ParsePrintCallbacks, // Parse and print each callback. ParseSyntaxOnly, // Parse and perform semantic analysis. @@ -102,6 +103,8 @@ ProgAction(llvm::cl::desc("Choose output type:"), llvm::cl::ZeroOrMore, "Print results of live variable analysis."), clEnumValN(WarnDeadStores, "warn-dead-stores", "Flag warnings of stores to dead variables."), + clEnumValN(WarnDeadStoresCheck, "warn-dead-stores-check", + "Check diagnostics emitted by --warn-dead-stores."), clEnumValN(WarnUninitVals, "warn-uninit-values", "Flag warnings of uses of unitialized variables."), clEnumValN(EmitLLVM, "emit-llvm", @@ -881,6 +884,12 @@ static void ProcessInputFile(Preprocessor &PP, unsigned MainFileID, ParseAST(PP, MainFileID, *C.get(), Stats); break; } + case WarnDeadStoresCheck: { + std::auto_ptr C(CreateDeadStoreChecker(PP.getDiagnostics())); + exit (CheckASTConsumer(PP, MainFileID, C)); + break; + } + case WarnUninitVals: { std::auto_ptr C(CreateUnitValsChecker(PP.getDiagnostics())); ParseAST(PP, MainFileID, *C.get(), Stats); diff --git a/clang/Driver/clang.h b/clang/Driver/clang.h index 06d49639e000..69b84431f4db 100644 --- a/clang/Driver/clang.h +++ b/clang/Driver/clang.h @@ -14,12 +14,15 @@ #ifndef LLVM_CLANG_CLANG_H #define LLVM_CLANG_CLANG_H +#include + namespace clang { class Preprocessor; struct LangOptions; class MinimalAction; class TargetInfo; class Diagnostic; +class ASTConsumer; /// DoPrintPreprocessedInput - Implement -E mode. void DoPrintPreprocessedInput(unsigned MainFileID, Preprocessor &PP, @@ -39,6 +42,10 @@ void EmitLLVMFromASTs(Preprocessor &PP, unsigned MainFileID, /// CheckDiagnostics - Implement the -parse-ast-check diagnostic verifier. bool CheckDiagnostics(Preprocessor &PP, unsigned MainFileID); + +/// CheckASTConsumer - Implement diagnostic checking for AST consumers. +bool CheckASTConsumer(Preprocessor &PP, unsigned MainFileID, + std::auto_ptr C); } // end namespace clang