]> granicus.if.org Git - clang/commitdiff
Keep track of when "unrecoverable" errors occur, then allow
authorDouglas Gregor <dgregor@apple.com>
Wed, 6 Jul 2011 17:40:26 +0000 (17:40 +0000)
committerDouglas Gregor <dgregor@apple.com>
Wed, 6 Jul 2011 17:40:26 +0000 (17:40 +0000)
clang_saveTranslationUnit() to save a PCH file if the only errors it
contains are recoverable errors. Fixes <rdar://problem/9727804>.

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

include/clang/Basic/Diagnostic.h
lib/Basic/Diagnostic.cpp
lib/Basic/DiagnosticIDs.cpp
lib/Frontend/ASTUnit.cpp
test/Index/werror.c [new file with mode: 0644]

index 9f12c548f51f2ca4b90a1b9123d783c2365ef23d..3b3ee4d4b0ce22fd072de98da2174feea8286641 100644 (file)
@@ -251,6 +251,9 @@ private:
   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 @@ public:
 
   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) {
index 11887ab0fe95c85af8d3862ef1fc15a0b95c554d..e0ef53d00de630eb41e95950967297f19536842a 100644 (file)
@@ -86,10 +86,12 @@ bool Diagnostic::popMappings(SourceLocation Loc) {
 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
index b5b48cb21318e71e0810931be4fdc4f72be29256..147ba7e99e74e989346369c529bbbb8957e58396 100644 (file)
@@ -686,9 +686,11 @@ bool DiagnosticIDs::ProcessDiag(Diagnostic &Diag) const {
 
   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 @@ bool DiagnosticIDs::isUnrecoverable(unsigned DiagID) const {
   }
 
   // Only errors may be unrecoverable.
-  if (getBuiltinDiagClass(DiagID) < DiagnosticIDs::Error)
+  if (getBuiltinDiagClass(DiagID) < CLASS_ERROR)
     return false;
 
   if (DiagID == diag::err_unavailable ||
index 8f61d6a8c2dee576271904c6bc5ec75ce875f155..4407d2d3e22b1fe5c184c3c7613b633df32e2bfe 100644 (file)
@@ -2288,7 +2288,7 @@ void ASTUnit::CodeComplete(llvm::StringRef File, unsigned Line, unsigned Column,
 }
 
 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 
diff --git a/test/Index/werror.c b/test/Index/werror.c
new file mode 100644 (file)
index 0000000..150095d
--- /dev/null
@@ -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
+