]> granicus.if.org Git - clang/commitdiff
Added "CheckASTConsumer", a function that generalizes
authorTed Kremenek <kremenek@apple.com>
Tue, 25 Sep 2007 18:37:20 +0000 (18:37 +0000)
committerTed Kremenek <kremenek@apple.com>
Tue, 25 Sep 2007 18:37:20 +0000 (18:37 +0000)
"CheckDiagnostics" (used for -parse-ast-check) to check the
diagnostics of any ASTConsumer.

Reimplemented CheckDiagnostics to use CheckASTConsumer instead.

Added driver option -warn-dead-stores-check, which checks the
diagnostics generated by the DeadStores checker.  This is implemented
using CheckASTConsumer.111

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@42310 91177308-0d34-0410-b5e6-96231b3b80d8

Driver/DiagChecker.cpp
Driver/clang.cpp
Driver/clang.h

index 48d804978022bfdbe0b41725167a46d0e1b2948d..21c3454bfdc469240e81b000c98a346be35c8cee 100644 (file)
@@ -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<ASTConsumer>(new ASTConsumer()));
 }
 
+/// CheckASTConsumer - Implement diagnostic checking for AST consumers.
+bool clang::CheckASTConsumer(Preprocessor &PP, unsigned MainFileID,
+                             std::auto_ptr<ASTConsumer> C) {
+
+  // Local scope for ASTConsumer to auto release the consumer ...
+  { std::auto_ptr<ASTConsumer> 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);
 }
-
-
index 77a568adac8aeab38d5419ea7db3e0e139e6e6c8..6ff5580f2ca16672cac2d0d3217c28f516eaabb0 100644 (file)
@@ -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<ASTConsumer> C(CreateDeadStoreChecker(PP.getDiagnostics()));
+    exit (CheckASTConsumer(PP, MainFileID, C));
+    break;
+  }
+      
   case WarnUninitVals: {
     std::auto_ptr<ASTConsumer> C(CreateUnitValsChecker(PP.getDiagnostics()));
     ParseAST(PP, MainFileID, *C.get(), Stats);
index 06d49639e000a57fc46c17e0d0101147ab934f58..69b84431f4dbddeb3d9b99d19ee192f496154692 100644 (file)
 #ifndef LLVM_CLANG_CLANG_H
 #define LLVM_CLANG_CLANG_H
 
+#include <memory>
+
 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<ASTConsumer> C);
 
 }  // end namespace clang