[cfe-commits] r134503 - in /cfe/trunk: include/clang/Basic/Diagnostic.h lib/Basic/Diagnostic.cpp lib/Basic/DiagnosticIDs.cpp lib/Frontend/ASTUnit.cpp test/Index/werror.c

Douglas Gregor dgregor at apple.com
Wed Jul 6 10:40:26 PDT 2011


Author: dgregor
Date: Wed Jul  6 12:40:26 2011
New Revision: 134503

URL: http://llvm.org/viewvc/llvm-project?rev=134503&view=rev
Log:
Keep track of when "unrecoverable" errors occur, then allow
clang_saveTranslationUnit() to save a PCH file if the only errors it
contains are recoverable errors. Fixes <rdar://problem/9727804>.

Added:
    cfe/trunk/test/Index/werror.c
Modified:
    cfe/trunk/include/clang/Basic/Diagnostic.h
    cfe/trunk/lib/Basic/Diagnostic.cpp
    cfe/trunk/lib/Basic/DiagnosticIDs.cpp
    cfe/trunk/lib/Frontend/ASTUnit.cpp

Modified: cfe/trunk/include/clang/Basic/Diagnostic.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Diagnostic.h?rev=134503&r1=134502&r2=134503&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/Diagnostic.h (original)
+++ cfe/trunk/include/clang/Basic/Diagnostic.h Wed Jul  6 12:40:26 2011
@@ -251,6 +251,9 @@
   bool ErrorOccurred;
   bool FatalErrorOccurred;
 
+  /// \brief Indicates that an unrecoverable error has occurred.
+  bool UnrecoverableErrorOccurred;
+  
   /// \brief Toggles for DiagnosticErrorTrap to check whether an error occurred
   /// during a parsing section, e.g. during parsing a function.
   bool TrapErrorOccurred;
@@ -437,7 +440,12 @@
 
   bool hasErrorOccurred() const { return ErrorOccurred; }
   bool hasFatalErrorOccurred() const { return FatalErrorOccurred; }
-
+  
+  /// \brief Determine whether any kind of unrecoverable error has occurred.
+  bool hasUnrecoverableErrorOccurred() const {
+    return FatalErrorOccurred || UnrecoverableErrorOccurred;
+  }
+  
   unsigned getNumWarnings() const { return NumWarnings; }
 
   void setNumWarnings(unsigned NumWarnings) {

Modified: cfe/trunk/lib/Basic/Diagnostic.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Diagnostic.cpp?rev=134503&r1=134502&r2=134503&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/Diagnostic.cpp (original)
+++ cfe/trunk/lib/Basic/Diagnostic.cpp Wed Jul  6 12:40:26 2011
@@ -86,10 +86,12 @@
 void Diagnostic::Reset() {
   ErrorOccurred = false;
   FatalErrorOccurred = false;
+  UnrecoverableErrorOccurred = false;
   
   NumWarnings = 0;
   NumErrors = 0;
   NumErrorsSuppressed = 0;
+  
   CurDiagID = ~0U;
   // Set LastDiagLevel to an "unset" state. If we set it to 'Ignored', notes
   // using a Diagnostic associated to a translation unit that follow

Modified: cfe/trunk/lib/Basic/DiagnosticIDs.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/DiagnosticIDs.cpp?rev=134503&r1=134502&r2=134503&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/DiagnosticIDs.cpp (original)
+++ cfe/trunk/lib/Basic/DiagnosticIDs.cpp Wed Jul  6 12:40:26 2011
@@ -686,9 +686,11 @@
 
   if (DiagLevel >= DiagnosticIDs::Error) {
     Diag.TrapErrorOccurred = true;
-    if (isUnrecoverable(DiagID))
+    if (isUnrecoverable(DiagID)) {
       Diag.TrapUnrecoverableErrorOccurred = true;
-
+      Diag.UnrecoverableErrorOccurred = true;
+    }
+    
     if (Diag.Client->IncludeInDiagnosticCounts()) {
       Diag.ErrorOccurred = true;
       ++Diag.NumErrors;
@@ -733,7 +735,7 @@
   }
 
   // Only errors may be unrecoverable.
-  if (getBuiltinDiagClass(DiagID) < DiagnosticIDs::Error)
+  if (getBuiltinDiagClass(DiagID) < CLASS_ERROR)
     return false;
 
   if (DiagID == diag::err_unavailable ||

Modified: cfe/trunk/lib/Frontend/ASTUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ASTUnit.cpp?rev=134503&r1=134502&r2=134503&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/ASTUnit.cpp (original)
+++ cfe/trunk/lib/Frontend/ASTUnit.cpp Wed Jul  6 12:40:26 2011
@@ -2288,7 +2288,7 @@
 }
 
 CXSaveError ASTUnit::Save(llvm::StringRef File) {
-  if (getDiagnostics().hasErrorOccurred())
+  if (getDiagnostics().hasUnrecoverableErrorOccurred())
     return CXSaveError_TranslationErrors;
   
   // FIXME: Can we somehow regenerate the stat cache here, or do we need to 

Added: cfe/trunk/test/Index/werror.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/werror.c?rev=134503&view=auto
==============================================================================
--- cfe/trunk/test/Index/werror.c (added)
+++ cfe/trunk/test/Index/werror.c Wed Jul  6 12:40:26 2011
@@ -0,0 +1,15 @@
+inline int *get_int_ptr(float *fp) {
+  return fp;
+}
+
+#ifdef FATAL
+void fatal(int);
+void fatal(float);
+#endif
+
+// CHECK-FATAL: translation errors
+
+// RUN: c-index-test -write-pch %t.pch -Werror %s
+// RUN: not c-index-test -write-pch %t.pch -DFATAL -Werror %s 2>%t.err
+// RUN: FileCheck -check-prefix=CHECK-FATAL %s < %t.err
+





More information about the cfe-commits mailing list