aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/clang/Basic/Diagnostic.h10
-rw-r--r--lib/Basic/Diagnostic.cpp2
-rw-r--r--lib/Basic/DiagnosticIDs.cpp8
-rw-r--r--lib/Frontend/ASTUnit.cpp2
-rw-r--r--test/Index/werror.c15
5 files changed, 32 insertions, 5 deletions
diff --git a/include/clang/Basic/Diagnostic.h b/include/clang/Basic/Diagnostic.h
index 9f12c548f5..3b3ee4d4b0 100644
--- a/include/clang/Basic/Diagnostic.h
+++ b/include/clang/Basic/Diagnostic.h
@@ -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) {
diff --git a/lib/Basic/Diagnostic.cpp b/lib/Basic/Diagnostic.cpp
index 11887ab0fe..e0ef53d00d 100644
--- a/lib/Basic/Diagnostic.cpp
+++ b/lib/Basic/Diagnostic.cpp
@@ -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
diff --git a/lib/Basic/DiagnosticIDs.cpp b/lib/Basic/DiagnosticIDs.cpp
index b5b48cb213..147ba7e99e 100644
--- a/lib/Basic/DiagnosticIDs.cpp
+++ b/lib/Basic/DiagnosticIDs.cpp
@@ -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 ||
diff --git a/lib/Frontend/ASTUnit.cpp b/lib/Frontend/ASTUnit.cpp
index 8f61d6a8c2..4407d2d3e2 100644
--- a/lib/Frontend/ASTUnit.cpp
+++ b/lib/Frontend/ASTUnit.cpp
@@ -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
index 0000000000..150095d859
--- /dev/null
+++ b/test/Index/werror.c
@@ -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
+