]> granicus.if.org Git - clang/commitdiff
Refactored driver so that any action that is implemented using an
authorTed Kremenek <kremenek@apple.com>
Wed, 26 Sep 2007 18:39:29 +0000 (18:39 +0000)
committerTed Kremenek <kremenek@apple.com>
Wed, 26 Sep 2007 18:39:29 +0000 (18:39 +0000)
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
Driver/clang.cpp
Driver/clang.h

index b921fd19a55446561273a78739775fe02097d943..8ffd5eea5cf9df190b5168ee07f19d731cf017b6 100644 (file)
@@ -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<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;
index 6ff5580f2ca16672cac2d0d3217c28f516eaabb0..630ab0723ae7904726c2ca6fd0aaf18bdddd7f64 100644 (file)
@@ -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<bool>
 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 @@ 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<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);
+  case WarnUninitVals:
+    Consumer = CreateUnitValsChecker(PP.getDiagnostics());
     break;
-  }    
-  case EmitLLVM: {
-    std::auto_ptr<ASTConsumer> 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) {
index 69b84431f4dbddeb3d9b99d19ee192f496154692..e4ae3b87bfcb935c87742dd83d7148c9a4731cef 100644 (file)
@@ -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<ASTConsumer> C);
+bool CheckASTConsumer(Preprocessor &PP, unsigned MainFileID, ASTConsumer* C);
+
 
 }  // end namespace clang