[cfe-commits] r42362 - in /cfe/trunk/Driver: DiagChecker.cpp clang.cpp clang.h
Ted Kremenek
kremenek at apple.com
Wed Sep 26 11:39:32 PDT 2007
Author: kremenek
Date: Wed Sep 26 13:39:29 2007
New Revision: 42362
URL: http://llvm.org/viewvc/llvm-project?rev=42362&view=rev
Log:
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".
Modified:
cfe/trunk/Driver/DiagChecker.cpp
cfe/trunk/Driver/clang.cpp
cfe/trunk/Driver/clang.h
Modified: cfe/trunk/Driver/DiagChecker.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/DiagChecker.cpp?rev=42362&r1=42361&r2=42362&view=diff
==============================================================================
--- cfe/trunk/Driver/DiagChecker.cpp (original)
+++ cfe/trunk/Driver/DiagChecker.cpp Wed Sep 26 13:39:29 2007
@@ -223,21 +223,12 @@
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<ASTConsumer>(new ASTConsumer()));
-}
/// CheckASTConsumer - Implement diagnostic checking for AST consumers.
bool clang::CheckASTConsumer(Preprocessor &PP, unsigned MainFileID,
- std::auto_ptr<ASTConsumer> C) {
+ ASTConsumer* C) {
- // Local scope to auto release the consumer ...
- { std::auto_ptr<ASTConsumer> Consumer(C);
- ParseAST(PP, MainFileID, *Consumer.get()); }
+ ParseAST(PP, MainFileID, *C);
// Gather the set of expected diagnostics.
DiagList ExpectedErrors, ExpectedWarnings;
Modified: cfe/trunk/Driver/clang.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/clang.cpp?rev=42362&r1=42361&r2=42362&view=diff
==============================================================================
--- cfe/trunk/Driver/clang.cpp (original)
+++ cfe/trunk/Driver/clang.cpp Wed Sep 26 13:39:29 2007
@@ -103,8 +103,6 @@
"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 @@
WarnUnusedMacros("Wunused_macros",
llvm::cl::desc("Warn for unused macros in the main translation unit"));
+static llvm::cl::opt<bool>
+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 @@
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,64 +852,57 @@
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<ASTConsumer> C(CreateASTPrinter());
- ParseAST(PP, MainFileID, *C.get(), Stats);
+
+ case ParseASTPrint:
+ Consumer = CreateASTPrinter();
break;
- }
- case ParseASTDump: {
- std::auto_ptr<ASTConsumer> C(CreateASTDumper());
- ParseAST(PP, MainFileID, *C.get(), Stats);
+
+ case ParseASTDump:
+ Consumer = CreateASTDumper();
break;
- }
- case ParseASTView: {
- std::auto_ptr<ASTConsumer> C(CreateASTViewer());
- ParseAST(PP, MainFileID, *C.get(), Stats);
+
+ case ParseASTView:
+ Consumer = CreateASTViewer();
break;
- }
+
case ParseCFGDump:
- case ParseCFGView: {
- std::auto_ptr<ASTConsumer> C(CreateCFGDumper(ProgAction == ParseCFGView));
- ParseAST(PP, MainFileID, *C.get(), Stats);
+ case ParseCFGView:
+ Consumer = CreateCFGDumper(ProgAction == ParseCFGView);
break;
- }
- case AnalysisLiveVariables: {
- std::auto_ptr<ASTConsumer> C(CreateLiveVarAnalyzer());
- ParseAST(PP, MainFileID, *C.get(), Stats);
- break;
- }
- case WarnDeadStores: {
- std::auto_ptr<ASTConsumer> C(CreateDeadStoreChecker(PP.getDiagnostics()));
- ParseAST(PP, MainFileID, *C.get(), Stats);
+
+ case AnalysisLiveVariables:
+ Consumer = CreateLiveVarAnalyzer();
break;
- }
- case WarnDeadStoresCheck: {
- std::auto_ptr<ASTConsumer> C(CreateDeadStoreChecker(PP.getDiagnostics()));
- exit (CheckASTConsumer(PP, MainFileID, C));
+
+ case WarnDeadStores:
+ Consumer = CreateDeadStoreChecker(PP.getDiagnostics());
break;
- }
- case WarnUninitVals: {
- std::auto_ptr<ASTConsumer> C(CreateUnitValsChecker(PP.getDiagnostics()));
- ParseAST(PP, MainFileID, *C.get(), Stats);
- break;
- }
- case EmitLLVM: {
- std::auto_ptr<ASTConsumer> C(CreateLLVMEmitter(PP.getDiagnostics()));
- ParseAST(PP, MainFileID, *C.get(), Stats);
+ case WarnUninitVals:
+ Consumer = CreateUnitValsChecker(PP.getDiagnostics());
break;
- }
- case ParseASTCheck:
- exit(CheckDiagnostics(PP, MainFileID));
+
+ case EmitLLVM:
+ Consumer = CreateLLVMEmitter(PP.getDiagnostics());
break;
}
+ if (Consumer) {
+ if (PerformDiagnosticsCheck)
+ exit (CheckASTConsumer(PP, MainFileID, Consumer));
+ else
+ ParseAST(PP, MainFileID, *Consumer, Stats);
+
+ delete Consumer;
+ }
+
if (Stats) {
fprintf(stderr, "\nSTATISTICS FOR '%s':\n", InFile.c_str());
PP.PrintStats();
Modified: cfe/trunk/Driver/clang.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/clang.h?rev=42362&r1=42361&r2=42362&view=diff
==============================================================================
--- cfe/trunk/Driver/clang.h (original)
+++ cfe/trunk/Driver/clang.h Wed Sep 26 13:39:29 2007
@@ -40,12 +40,9 @@
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<ASTConsumer> C);
+bool CheckASTConsumer(Preprocessor &PP, unsigned MainFileID, ASTConsumer* C);
+
} // end namespace clang
More information about the cfe-commits
mailing list