]> granicus.if.org Git - clang/commitdiff
Switch -verify implementation to use VerifyDiagnosticClient.
authorDaniel Dunbar <daniel@zuster.org>
Sat, 14 Nov 2009 03:24:39 +0000 (03:24 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Sat, 14 Nov 2009 03:24:39 +0000 (03:24 +0000)
 - Not tested, but -verify with multiple inputs should work now.

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

lib/Frontend/CompilerInstance.cpp
tools/clang-cc/clang-cc.cpp

index 0352c4546045320751e7335c5435e1e65f8ea00a..2877c63a4e2bc4eb7c020babd874aa78d0d0e06a 100644 (file)
@@ -20,8 +20,8 @@
 #include "clang/Frontend/ChainedDiagnosticClient.h"
 #include "clang/Frontend/PCHReader.h"
 #include "clang/Frontend/FrontendDiagnostic.h"
-#include "clang/Frontend/TextDiagnosticBuffer.h"
 #include "clang/Frontend/TextDiagnosticPrinter.h"
+#include "clang/Frontend/VerifyDiagnosticsClient.h"
 #include "clang/Frontend/Utils.h"
 #include "clang/Sema/CodeCompleteConsumer.h"
 #include "llvm/LLVMContext.h"
@@ -114,13 +114,12 @@ Diagnostic *CompilerInstance::createDiagnostics(const DiagnosticOptions &Opts,
                                                 int Argc, char **Argv) {
   // Create the diagnostic client for reporting errors or for
   // implementing -verify.
-  llvm::OwningPtr<DiagnosticClient> DiagClient;
-  if (Opts.VerifyDiagnostics) {
-    // When checking diagnostics, just buffer them up.
-    DiagClient.reset(new TextDiagnosticBuffer());
-  } else {
-    DiagClient.reset(new TextDiagnosticPrinter(llvm::errs(), Opts));
-  }
+  llvm::OwningPtr<DiagnosticClient> DiagClient(
+    new TextDiagnosticPrinter(llvm::errs(), Opts));
+
+  // Chain in -verify checker, if requested.
+  if (Opts.VerifyDiagnostics)
+    DiagClient.reset(new VerifyDiagnosticsClient(DiagClient.take()));
 
   if (!Opts.DumpBuildInformation.empty())
     SetUpBuildDumpLog(Opts, Argc, Argv, DiagClient);
index 6ae474289a64ad7feb231d86bb52730c0ba49552..c153ef52460201dacf5a02c24a50f0e38b621c30 100644 (file)
@@ -37,6 +37,7 @@
 #include "clang/Frontend/PreprocessorOptions.h"
 #include "clang/Frontend/PreprocessorOutputOptions.h"
 #include "clang/Frontend/Utils.h"
+#include "clang/Frontend/VerifyDiagnosticsClient.h"
 #include "clang/Lex/HeaderSearch.h"
 #include "clang/Lex/LexDiagnostic.h"
 #include "clang/Parse/Parser.h"
@@ -532,10 +533,6 @@ static void ProcessInputFile(CompilerInstance &CI, const std::string &InFile,
     CI.setASTContext(0);
   }
 
-  if (CI.getDiagnosticOpts().VerifyDiagnostics)
-    if (CheckDiagnostics(PP))
-      exit(1);
-
   if (FEOpts.ShowStats) {
     fprintf(stderr, "\nSTATISTICS FOR '%s':\n", InFile.c_str());
     PP.PrintStats();
@@ -734,12 +731,6 @@ int main(int argc, char **argv) {
   if (Clang.getFrontendOpts().ShowTimers)
     ClangFrontendTimer = new llvm::Timer("Clang front-end time");
 
-  if (Clang.getDiagnosticOpts().VerifyDiagnostics &&
-      Clang.getFrontendOpts().Inputs.size() > 1) {
-    fprintf(stderr, "-verify only works on single input files.\n");
-    return 1;
-  }
-
   // C++ visualization?
   if (!Clang.getFrontendOpts().ViewClassInheritance.empty())
     ProgAction = InheritanceView;
@@ -785,9 +776,13 @@ int main(int argc, char **argv) {
 
   delete ClangFrontendTimer;
 
-  // If verifying diagnostics and we reached here, all is well.
+  // Return the appropriate status when verifying diagnostics.
+  //
+  // FIXME: If we could make getNumErrors() do the right thing, we wouldn't need
+  // this.
   if (Clang.getDiagnosticOpts().VerifyDiagnostics)
-    return 0;
+    return static_cast<VerifyDiagnosticsClient&>(
+      Clang.getDiagnosticClient()).HadErrors();
 
   // Managed static deconstruction. Useful for making things like
   // -time-passes usable.