From d39bcd838f1980a9f5e3df23cf91c0c435f4b974 Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Wed, 26 Sep 2007 18:39:29 +0000 Subject: [PATCH] Refactored driver so that any action that is implemented using an ASTConsumer can also be verified using the diagnostics checker. From the command line, users may activate diagnostic checking using the "-verify" option. For example, "clang -verify -warn-dead-stores" checks if the warnings flagged by the dead store checker match those in the comments. Note that we still have the option "-parse-ast-check" for backwards comptability with existing test cases. This option is now equivalent to "-parse-ast -verify". git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@42362 91177308-0d34-0410-b5e6-96231b3b80d8 --- Driver/DiagChecker.cpp | 13 +------ Driver/clang.cpp | 88 +++++++++++++++++++++--------------------- Driver/clang.h | 7 +--- 3 files changed, 47 insertions(+), 61 deletions(-) diff --git a/Driver/DiagChecker.cpp b/Driver/DiagChecker.cpp index b921fd19a5..8ffd5eea5c 100644 --- a/Driver/DiagChecker.cpp +++ b/Driver/DiagChecker.cpp @@ -223,21 +223,12 @@ static bool CheckResults(Preprocessor &PP, return HadProblem; } -/// CheckDiagnostics - Implement the -parse-ast-check diagnostic verifier. -bool clang::CheckDiagnostics(Preprocessor &PP, unsigned MainFileID) { - // Parse the specified input file, building ASTs and performing sema, but - // doing nothing else. - 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) { + ASTConsumer* C) { - // Local scope to auto release the consumer ... - { std::auto_ptr Consumer(C); - ParseAST(PP, MainFileID, *Consumer.get()); } + ParseAST(PP, MainFileID, *C); // Gather the set of expected diagnostics. DiagList ExpectedErrors, ExpectedWarnings; diff --git a/Driver/clang.cpp b/Driver/clang.cpp index 6ff5580f2c..630ab0723a 100644 --- a/Driver/clang.cpp +++ b/Driver/clang.cpp @@ -103,8 +103,6 @@ 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", @@ -348,6 +346,9 @@ static llvm::cl::opt WarnUnusedMacros("Wunused_macros", llvm::cl::desc("Warn for unused macros in the main translation unit")); +static llvm::cl::opt +VerifyDiagnostics("verify", + llvm::cl::desc("Verify emitted diagnostics and warnings.")); /// InitializeDiagnostics - Initialize the diagnostic object, based on the /// current command line option settings. @@ -805,7 +806,11 @@ static void ProcessInputFile(Preprocessor &PP, unsigned MainFileID, TextDiagnostics &OurDiagnosticClient, HeaderSearch &HeaderInfo, const LangOptions &LangInfo) { + + ASTConsumer* Consumer = NULL; bool ClearSourceMgr = false; + bool PerformDiagnosticsCheck = VerifyDiagnostics; + switch (ProgAction) { default: fprintf(stderr, "Unexpected program action!\n"); @@ -847,62 +852,55 @@ static void ProcessInputFile(Preprocessor &PP, unsigned MainFileID, ParseFile(PP, CreatePrintParserActionsAction(), MainFileID); ClearSourceMgr = true; break; + + case ParseASTCheck: + PerformDiagnosticsCheck = true; case ParseSyntaxOnly: // -fsyntax-only - case BuildAST: { - ASTConsumer NullConsumer; - ParseAST(PP, MainFileID, NullConsumer, Stats); + case BuildAST: + Consumer = new ASTConsumer(); break; - } - case ParseASTPrint: { - std::auto_ptr C(CreateASTPrinter()); - ParseAST(PP, MainFileID, *C.get(), Stats); + + case ParseASTPrint: + Consumer = CreateASTPrinter(); break; - } - case ParseASTDump: { - std::auto_ptr C(CreateASTDumper()); - ParseAST(PP, MainFileID, *C.get(), Stats); + + case ParseASTDump: + Consumer = CreateASTDumper(); break; - } - case ParseASTView: { - std::auto_ptr C(CreateASTViewer()); - ParseAST(PP, MainFileID, *C.get(), Stats); + + case ParseASTView: + Consumer = CreateASTViewer(); break; - } + case ParseCFGDump: - case ParseCFGView: { - std::auto_ptr C(CreateCFGDumper(ProgAction == ParseCFGView)); - ParseAST(PP, MainFileID, *C.get(), Stats); + case ParseCFGView: + Consumer = CreateCFGDumper(ProgAction == ParseCFGView); break; - } - case AnalysisLiveVariables: { - std::auto_ptr C(CreateLiveVarAnalyzer()); - ParseAST(PP, MainFileID, *C.get(), Stats); - break; - } - case WarnDeadStores: { - std::auto_ptr C(CreateDeadStoreChecker(PP.getDiagnostics())); - ParseAST(PP, MainFileID, *C.get(), Stats); + + case AnalysisLiveVariables: + Consumer = CreateLiveVarAnalyzer(); break; - } - case WarnDeadStoresCheck: { - std::auto_ptr C(CreateDeadStoreChecker(PP.getDiagnostics())); - exit (CheckASTConsumer(PP, MainFileID, C)); + + case WarnDeadStores: + Consumer = CreateDeadStoreChecker(PP.getDiagnostics()); break; - } - case WarnUninitVals: { - std::auto_ptr C(CreateUnitValsChecker(PP.getDiagnostics())); - ParseAST(PP, MainFileID, *C.get(), Stats); + case WarnUninitVals: + Consumer = CreateUnitValsChecker(PP.getDiagnostics()); break; - } - case EmitLLVM: { - std::auto_ptr C(CreateLLVMEmitter(PP.getDiagnostics())); - ParseAST(PP, MainFileID, *C.get(), Stats); + + case EmitLLVM: + Consumer = CreateLLVMEmitter(PP.getDiagnostics()); break; } - case ParseASTCheck: - exit(CheckDiagnostics(PP, MainFileID)); - break; + + if (Consumer) { + if (PerformDiagnosticsCheck) + exit (CheckASTConsumer(PP, MainFileID, Consumer)); + else + ParseAST(PP, MainFileID, *Consumer, Stats); + + delete Consumer; } if (Stats) { diff --git a/Driver/clang.h b/Driver/clang.h index 69b84431f4..e4ae3b87bf 100644 --- a/Driver/clang.h +++ b/Driver/clang.h @@ -40,12 +40,9 @@ TargetInfo *CreateTargetInfo(Diagnostic &Diags); void EmitLLVMFromASTs(Preprocessor &PP, unsigned MainFileID, bool PrintStats); -/// 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); +bool CheckASTConsumer(Preprocessor &PP, unsigned MainFileID, ASTConsumer* C); + } // end namespace clang -- 2.40.0