]> granicus.if.org Git - clang/commitdiff
Teach TextDiagnosticPrinter to print out '-Werror' in addition to the warning flag...
authorTed Kremenek <kremenek@apple.com>
Fri, 25 Feb 2011 01:28:26 +0000 (01:28 +0000)
committerTed Kremenek <kremenek@apple.com>
Fri, 25 Feb 2011 01:28:26 +0000 (01:28 +0000)
For example:

t.c:7:9: error: using the result of an assignment as a condition without parentheses [-Werror,-Wparentheses]

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

include/clang/Basic/Diagnostic.h
include/clang/Basic/DiagnosticIDs.h
lib/Basic/DiagnosticIDs.cpp
lib/Frontend/TextDiagnosticPrinter.cpp
test/Sema/parentheses.c

index 19e7c91f53244693a8e42e2a626d3acd9a8ce0f0..3fc60d136b5c40a2eec6075dc78587b243b08fc4 100644 (file)
@@ -474,8 +474,9 @@ public:
   ///
   /// \param Loc The source location we are interested in finding out the
   /// diagnostic state. Can be null in order to query the latest state.
-  Level getDiagnosticLevel(unsigned DiagID, SourceLocation Loc) const {
-    return (Level)Diags->getDiagnosticLevel(DiagID, Loc, *this);
+  Level getDiagnosticLevel(unsigned DiagID, SourceLocation Loc,
+                           diag::Mapping *mapping = 0) const {
+    return (Level)Diags->getDiagnosticLevel(DiagID, Loc, *this, mapping);
   }
 
   /// Report - Issue the message to the client.  @c DiagID is a member of the
index b463805698516fe037571534c0ef41984f1ec8ac..2b03cae565c83daf73889ccaf5cd60f57e351544 100644 (file)
@@ -188,14 +188,16 @@ private:
   /// \param Loc The source location we are interested in finding out the
   /// diagnostic state. Can be null in order to query the latest state.
   DiagnosticIDs::Level getDiagnosticLevel(unsigned DiagID, SourceLocation Loc,
-                                          const Diagnostic &Diag) const;
+                                          const Diagnostic &Diag,
+                                          diag::Mapping *mapping = 0) const;
 
   /// getDiagnosticLevel - This is an internal implementation helper used when
   /// DiagClass is already known.
   DiagnosticIDs::Level getDiagnosticLevel(unsigned DiagID,
                                           unsigned DiagClass,
                                           SourceLocation Loc,
-                                          const Diagnostic &Diag) const;
+                                          const Diagnostic &Diag,
+                                          diag::Mapping *mapping = 0) const;
 
   /// ProcessDiag - This is the method used to report a diagnostic that is
   /// finally fully formed.
index 8725e7f9c0ccce47882928ae95502219a08893b3..553e4c929454f757390b87b2b5a36045532e9a80 100644 (file)
@@ -288,14 +288,15 @@ const char *DiagnosticIDs::getDescription(unsigned DiagID) const {
 /// the DiagnosticClient.
 DiagnosticIDs::Level
 DiagnosticIDs::getDiagnosticLevel(unsigned DiagID, SourceLocation Loc,
-                                  const Diagnostic &Diag) const {
+                                  const Diagnostic &Diag,
+                                  diag::Mapping *mapping) const {
   // Handle custom diagnostics, which cannot be mapped.
   if (DiagID >= diag::DIAG_UPPER_LIMIT)
     return CustomDiagInfo->getLevel(DiagID);
 
   unsigned DiagClass = getBuiltinDiagClass(DiagID);
   assert(DiagClass != CLASS_NOTE && "Cannot get diagnostic level of a note!");
-  return getDiagnosticLevel(DiagID, DiagClass, Loc, Diag);
+  return getDiagnosticLevel(DiagID, DiagClass, Loc, Diag, mapping);
 }
 
 /// \brief Based on the way the client configured the Diagnostic
@@ -307,7 +308,8 @@ DiagnosticIDs::getDiagnosticLevel(unsigned DiagID, SourceLocation Loc,
 DiagnosticIDs::Level
 DiagnosticIDs::getDiagnosticLevel(unsigned DiagID, unsigned DiagClass,
                                   SourceLocation Loc,
-                                  const Diagnostic &Diag) const {
+                                  const Diagnostic &Diag,
+                                  diag::Mapping *mapping) const {
   // Specific non-error diagnostics may be mapped to various levels from ignored
   // to error.  Errors can only be mapped to fatal.
   DiagnosticIDs::Level Result = DiagnosticIDs::Fatal;
@@ -323,6 +325,9 @@ DiagnosticIDs::getDiagnosticLevel(unsigned DiagID, unsigned DiagClass,
     MappingInfo = GetDefaultDiagMapping(DiagID);
     Diag.setDiagnosticMappingInternal(DiagID, MappingInfo, State, false, false);
   }
+  
+  if (mapping)
+    *mapping = (diag::Mapping) (MappingInfo & 7);
 
   switch (MappingInfo & 7) {
   default: assert(0 && "Unknown mapping!");
index 04c6a68023d9863291b4fd1b37a79551979e91c8..084915311dcc1875c6fbc2cc57b222b1d921c5aa 100644 (file)
@@ -905,9 +905,21 @@ void TextDiagnosticPrinter::HandleDiagnostic(Diagnostic::Level Level,
 
   std::string OptionName;
   if (DiagOpts->ShowOptionNames) {
+    // Was this a warning mapped to an error using -Werror or pragma?
+    if (Level == Diagnostic::Error &&
+        DiagnosticIDs::isBuiltinWarningOrExtension(Info.getID())) {
+      diag::Mapping mapping = diag::MAP_IGNORE;
+      Info.getDiags()->getDiagnosticLevel(Info.getID(), Info.getLocation(), 
+                                          &mapping);
+      if (mapping == diag::MAP_WARNING)
+        OptionName += "-Werror";
+    }
+
     if (const char *
           Opt = DiagnosticIDs::getWarningOptionForDiag(Info.getID())) {
-      OptionName = "-W";
+      if (!OptionName.empty())
+        OptionName += ',';
+      OptionName += "-W";
       OptionName += Opt;
     } else if (Info.getID() == diag::fatal_too_many_errors) {
       OptionName = "-ferror-limit=";
index 6d6fa1d4bd42fd5e9839b2757eb7bba76cf69e0c..b45d8512f6bf7f39e1098141728841e40b027ac8 100644 (file)
@@ -37,3 +37,7 @@ void bitwise_rel(unsigned i) {
   (void)(i && i || 0); // no warning.
   (void)(0 || i && i); // no warning.
 }
+
+// RUN: %clang_cc1 -fsyntax-only -Wparentheses -Werror -fdiagnostics-show-option %s 2>&1 | FileCheck %s
+// CHECK: error: using the result of an assignment as a condition without parentheses [-Werror,-Wparentheses]
+