r223525 - Make DiagnosticErrorTrap work even if SuppressAllDiagnostics is enabled.
Richard Smith
richard-llvm at metafoo.co.uk
Fri Dec 5 13:52:59 PST 2014
Author: rsmith
Date: Fri Dec 5 15:52:58 2014
New Revision: 223525
URL: http://llvm.org/viewvc/llvm-project?rev=223525&view=rev
Log:
Make DiagnosticErrorTrap work even if SuppressAllDiagnostics is enabled.
Patch by Brad King!
Added:
cfe/trunk/unittests/Basic/DiagnosticTest.cpp
Modified:
cfe/trunk/lib/Basic/DiagnosticIDs.cpp
cfe/trunk/unittests/Basic/CMakeLists.txt
Modified: cfe/trunk/lib/Basic/DiagnosticIDs.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/DiagnosticIDs.cpp?rev=223525&r1=223524&r2=223525&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/DiagnosticIDs.cpp (original)
+++ cfe/trunk/lib/Basic/DiagnosticIDs.cpp Fri Dec 5 15:52:58 2014
@@ -606,9 +606,6 @@ StringRef DiagnosticIDs::getNearestOptio
bool DiagnosticIDs::ProcessDiag(DiagnosticsEngine &Diag) const {
Diagnostic Info(&Diag);
- if (Diag.SuppressAllDiagnostics)
- return false;
-
assert(Diag.getClient() && "DiagnosticClient not set!");
// Figure out the diagnostic level of this message.
@@ -616,6 +613,17 @@ bool DiagnosticIDs::ProcessDiag(Diagnost
DiagnosticIDs::Level DiagLevel
= getDiagnosticLevel(DiagID, Info.getLocation(), Diag);
+ // Update counts for DiagnosticErrorTrap even if a fatal error occurred
+ // or diagnostics are suppressed.
+ if (DiagLevel >= DiagnosticIDs::Error) {
+ ++Diag.TrapNumErrorsOccurred;
+ if (isUnrecoverable(DiagID))
+ ++Diag.TrapNumUnrecoverableErrorsOccurred;
+ }
+
+ if (Diag.SuppressAllDiagnostics)
+ return false;
+
if (DiagLevel != DiagnosticIDs::Note) {
// Record that a fatal error occurred only when we see a second
// non-note diagnostic. This allows notes to be attached to the
@@ -627,13 +635,6 @@ bool DiagnosticIDs::ProcessDiag(Diagnost
Diag.LastDiagLevel = DiagLevel;
}
- // Update counts for DiagnosticErrorTrap even if a fatal error occurred.
- if (DiagLevel >= DiagnosticIDs::Error) {
- ++Diag.TrapNumErrorsOccurred;
- if (isUnrecoverable(DiagID))
- ++Diag.TrapNumUnrecoverableErrorsOccurred;
- }
-
// If a fatal error has already been emitted, silence all subsequent
// diagnostics.
if (Diag.FatalErrorOccurred) {
Modified: cfe/trunk/unittests/Basic/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Basic/CMakeLists.txt?rev=223525&r1=223524&r2=223525&view=diff
==============================================================================
--- cfe/trunk/unittests/Basic/CMakeLists.txt (original)
+++ cfe/trunk/unittests/Basic/CMakeLists.txt Fri Dec 5 15:52:58 2014
@@ -4,6 +4,7 @@ set(LLVM_LINK_COMPONENTS
add_clang_unittest(BasicTests
CharInfoTest.cpp
+ DiagnosticTest.cpp
FileManagerTest.cpp
SourceManagerTest.cpp
VirtualFileSystemTest.cpp
Added: cfe/trunk/unittests/Basic/DiagnosticTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Basic/DiagnosticTest.cpp?rev=223525&view=auto
==============================================================================
--- cfe/trunk/unittests/Basic/DiagnosticTest.cpp (added)
+++ cfe/trunk/unittests/Basic/DiagnosticTest.cpp Fri Dec 5 15:52:58 2014
@@ -0,0 +1,49 @@
+//===- unittests/Basic/DiagnosticTest.cpp -- Diagnostic engine tests ------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/DiagnosticIDs.h"
+#include "gtest/gtest.h"
+
+using namespace llvm;
+using namespace clang;
+
+namespace {
+
+// Check that DiagnosticErrorTrap works with SuppressAllDiagnostics.
+TEST(DiagnosticTest, suppressAndTrap) {
+ DiagnosticsEngine Diags(new DiagnosticIDs(),
+ new DiagnosticOptions,
+ new IgnoringDiagConsumer());
+ Diags.setSuppressAllDiagnostics(true);
+
+ {
+ DiagnosticErrorTrap trap(Diags);
+
+ // Diag that would set UncompilableErrorOccurred and ErrorOccurred.
+ Diags.Report(diag::err_target_unknown_triple) << "unknown";
+
+ // Diag that would set UnrecoverableErrorOccurred and ErrorOccurred.
+ Diags.Report(diag::err_cannot_open_file) << "file" << "error";
+
+ // Diag that would set FatalErrorOccurred
+ // (via non-note following a fatal error).
+ Diags.Report(diag::warn_mt_message) << "warning";
+
+ EXPECT_TRUE(trap.hasErrorOccurred());
+ EXPECT_TRUE(trap.hasUnrecoverableErrorOccurred());
+ }
+
+ EXPECT_FALSE(Diags.hasErrorOccurred());
+ EXPECT_FALSE(Diags.hasFatalErrorOccurred());
+ EXPECT_FALSE(Diags.hasUncompilableErrorOccurred());
+ EXPECT_FALSE(Diags.hasUnrecoverableErrorOccurred());
+}
+
+}
More information about the cfe-commits
mailing list