[cfe-commits] r136447 - in /cfe/trunk: include/clang/Basic/Diagnostic.h lib/Basic/Diagnostic.cpp lib/Basic/DiagnosticIDs.cpp test/SemaCXX/scope-check.cpp
Argyrios Kyrtzidis
akyrtzi at gmail.com
Thu Jul 28 18:25:44 PDT 2011
Author: akirtzidis
Date: Thu Jul 28 20:25:44 2011
New Revision: 136447
URL: http://llvm.org/viewvc/llvm-project?rev=136447&view=rev
Log:
Make DiagnosticErrorTrap keep a count of the errors that occurred so multiple
DiagnosticErrorTraps can be composed (e.g. a trap inside another trap).
Fixes http://llvm.org/PR10462 & rdar://9852007.
Modified:
cfe/trunk/include/clang/Basic/Diagnostic.h
cfe/trunk/lib/Basic/Diagnostic.cpp
cfe/trunk/lib/Basic/DiagnosticIDs.cpp
cfe/trunk/test/SemaCXX/scope-check.cpp
Modified: cfe/trunk/include/clang/Basic/Diagnostic.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Diagnostic.h?rev=136447&r1=136446&r2=136447&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/Diagnostic.h (original)
+++ cfe/trunk/include/clang/Basic/Diagnostic.h Thu Jul 28 20:25:44 2011
@@ -255,10 +255,10 @@
/// \brief Indicates that an unrecoverable error has occurred.
bool UnrecoverableErrorOccurred;
- /// \brief Toggles for DiagnosticErrorTrap to check whether an error occurred
+ /// \brief Counts for DiagnosticErrorTrap to check whether an error occurred
/// during a parsing section, e.g. during parsing a function.
- bool TrapErrorOccurred;
- bool TrapUnrecoverableErrorOccurred;
+ unsigned TrapNumErrorsOccurred;
+ unsigned TrapNumUnrecoverableErrorsOccurred;
/// LastDiagLevel - This is the level of the last diagnostic emitted. This is
/// used to emit continuation diagnostics with the same level as the
@@ -639,6 +639,8 @@
/// queried.
class DiagnosticErrorTrap {
Diagnostic &Diag;
+ unsigned NumErrors;
+ unsigned NumUnrecoverableErrors;
public:
explicit DiagnosticErrorTrap(Diagnostic &Diag)
@@ -647,19 +649,19 @@
/// \brief Determine whether any errors have occurred since this
/// object instance was created.
bool hasErrorOccurred() const {
- return Diag.TrapErrorOccurred;
+ return Diag.TrapNumErrorsOccurred > NumErrors;
}
/// \brief Determine whether any unrecoverable errors have occurred since this
/// object instance was created.
bool hasUnrecoverableErrorOccurred() const {
- return Diag.TrapUnrecoverableErrorOccurred;
+ return Diag.TrapNumUnrecoverableErrorsOccurred > NumUnrecoverableErrors;
}
// Set to initial state of "no errors occurred".
void reset() {
- Diag.TrapErrorOccurred = false;
- Diag.TrapUnrecoverableErrorOccurred = false;
+ NumErrors = Diag.TrapNumErrorsOccurred;
+ NumUnrecoverableErrors = Diag.TrapNumUnrecoverableErrorsOccurred;
}
};
Modified: cfe/trunk/lib/Basic/Diagnostic.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Diagnostic.cpp?rev=136447&r1=136446&r2=136447&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/Diagnostic.cpp (original)
+++ cfe/trunk/lib/Basic/Diagnostic.cpp Thu Jul 28 20:25:44 2011
@@ -92,6 +92,8 @@
NumWarnings = 0;
NumErrors = 0;
NumErrorsSuppressed = 0;
+ TrapNumErrorsOccurred = 0;
+ TrapNumUnrecoverableErrorsOccurred = 0;
CurDiagID = ~0U;
// Set LastDiagLevel to an "unset" state. If we set it to 'Ignored', notes
Modified: cfe/trunk/lib/Basic/DiagnosticIDs.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/DiagnosticIDs.cpp?rev=136447&r1=136446&r2=136447&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/DiagnosticIDs.cpp (original)
+++ cfe/trunk/lib/Basic/DiagnosticIDs.cpp Thu Jul 28 20:25:44 2011
@@ -665,6 +665,13 @@
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) {
@@ -685,11 +692,8 @@
return false;
if (DiagLevel >= DiagnosticIDs::Error) {
- Diag.TrapErrorOccurred = true;
- if (isUnrecoverable(DiagID)) {
- Diag.TrapUnrecoverableErrorOccurred = true;
+ if (isUnrecoverable(DiagID))
Diag.UnrecoverableErrorOccurred = true;
- }
if (Diag.Client->IncludeInDiagnosticCounts()) {
Diag.ErrorOccurred = true;
Modified: cfe/trunk/test/SemaCXX/scope-check.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/scope-check.cpp?rev=136447&r1=136446&r2=136447&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/scope-check.cpp (original)
+++ cfe/trunk/test/SemaCXX/scope-check.cpp Thu Jul 28 20:25:44 2011
@@ -171,3 +171,24 @@
}
}
}
+
+// http://llvm.org/PR10462
+namespace PR10462 {
+enum MyEnum {
+ something_valid,
+ something_invalid
+};
+
+bool recurse() {
+ MyEnum K;
+ switch (K) { // expected-warning {{enumeration value 'something_invalid' not handled in switch}}
+ case something_valid:
+ case what_am_i_thinking: // expected-error {{use of undeclared identifier}}
+ int *X = 0;
+ if (recurse()) {
+ }
+
+ break;
+ }
+}
+}
More information about the cfe-commits
mailing list