[cfe-commits] r140752 - in /cfe/trunk: include/clang/Basic/DiagnosticIDs.h lib/Basic/DiagnosticIDs.cpp lib/Frontend/TextDiagnosticPrinter.cpp test/Frontend/diagnostics-option-names.c
Daniel Dunbar
daniel at zuster.org
Wed Sep 28 18:01:08 PDT 2011
Author: ddunbar
Date: Wed Sep 28 20:01:08 2011
New Revision: 140752
URL: http://llvm.org/viewvc/llvm-project?rev=140752&view=rev
Log:
Basic/Diagnostics: Add an isDefaultMappingAsError method, and switch TextDiagnosticPrinter to use that instead of extracting the current mapping via getDiagnosticLevel, which fixes one class of corner cases w.r.t. printing the "-Werror" diagnostic option marker.
- The TextDiagnosticPrinter code is still fragile as it is just "reverse engineering" what the diagnostic engine is doing. Not my current priority to fix though.
Added:
cfe/trunk/test/Frontend/diagnostics-option-names.c
Modified:
cfe/trunk/include/clang/Basic/DiagnosticIDs.h
cfe/trunk/lib/Basic/DiagnosticIDs.cpp
cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticIDs.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticIDs.h?rev=140752&r1=140751&r2=140752&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticIDs.h (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticIDs.h Wed Sep 28 20:01:08 2011
@@ -110,6 +110,10 @@
/// NOTEs.
static bool isBuiltinWarningOrExtension(unsigned DiagID);
+ /// \brief Return true if the specified diagnostic is mapped to errors by
+ /// default.
+ static bool isDefaultMappingAsError(unsigned DiagID);
+
/// \brief Determine whether the given built-in diagnostic ID is a
/// Note.
static bool isBuiltinNote(unsigned DiagID);
Modified: cfe/trunk/lib/Basic/DiagnosticIDs.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/DiagnosticIDs.cpp?rev=140752&r1=140751&r2=140752&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/DiagnosticIDs.cpp (original)
+++ cfe/trunk/lib/Basic/DiagnosticIDs.cpp Wed Sep 28 20:01:08 2011
@@ -458,6 +458,13 @@
return true;
}
+bool DiagnosticIDs::isDefaultMappingAsError(unsigned DiagID) {
+ if (DiagID >= diag::DIAG_UPPER_LIMIT)
+ return false;
+
+ return GetDefaultDiagMapping(DiagID) == diag::MAP_ERROR;
+}
+
/// getDescription - Given a diagnostic ID, return a description of the
/// issue.
StringRef DiagnosticIDs::getDescription(unsigned DiagID) const {
Modified: cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp?rev=140752&r1=140751&r2=140752&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp (original)
+++ cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp Wed Sep 28 20:01:08 2011
@@ -942,16 +942,20 @@
return;
}
- // Was this a warning mapped to an error using -Werror or pragma?
+ // The code below is somewhat fragile because we are essentially trying to
+ // report to the user what happened by inferring what the diagnostic engine
+ // did. Eventually it might make more sense to have the diagnostic engine
+ // include some "why" information in the diagnostic.
+
+ // If this is a warning which has been mapped to an error by the user (as
+ // inferred by checking whether the default mapping is to an error) then
+ // flag it as such. Note that diagnostics could also have been mapped by a
+ // pragma, but we don't currently have a way to distinguish this.
if (Level == DiagnosticsEngine::Error &&
- DiagnosticIDs::isBuiltinWarningOrExtension(Info.getID())) {
- diag::Mapping mapping = diag::MAP_IGNORE;
- Info.getDiags()->getDiagnosticLevel(Info.getID(), Info.getLocation(),
- &mapping);
- if (mapping == diag::MAP_WARNING) {
- OS << " [-Werror";
- Started = true;
- }
+ DiagnosticIDs::isBuiltinWarningOrExtension(Info.getID()) &&
+ !DiagnosticIDs::isDefaultMappingAsError(Info.getID())) {
+ OS << " [-Werror";
+ Started = true;
}
// If the diagnostic is an extension diagnostic and not enabled by default
Added: cfe/trunk/test/Frontend/diagnostics-option-names.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Frontend/diagnostics-option-names.c?rev=140752&view=auto
==============================================================================
--- cfe/trunk/test/Frontend/diagnostics-option-names.c (added)
+++ cfe/trunk/test/Frontend/diagnostics-option-names.c Wed Sep 28 20:01:08 2011
@@ -0,0 +1,8 @@
+// RUN: not %clang_cc1 -fdiagnostics-show-option -Werror -Weverything %s 2> %t
+// RUN: FileCheck < %t %s
+
+int f0(int, unsigned);
+int f0(int x, unsigned y) {
+// CHECK: comparison of integers of different signs{{.*}} [-Werror,-Wsign-compare]
+ return x < y; // expected-error {{ : 'int' and 'unsigned int' }}
+}
More information about the cfe-commits
mailing list