[cfe-commits] r126466 - in /cfe/trunk: include/clang/Basic/Diagnostic.h include/clang/Basic/DiagnosticIDs.h lib/Basic/DiagnosticIDs.cpp lib/Frontend/TextDiagnosticPrinter.cpp test/Sema/parentheses.c

Ted Kremenek kremenek at apple.com
Thu Feb 24 17:28:26 PST 2011


Author: kremenek
Date: Thu Feb 24 19:28:26 2011
New Revision: 126466

URL: http://llvm.org/viewvc/llvm-project?rev=126466&view=rev
Log:
Teach TextDiagnosticPrinter to print out '-Werror' in addition to the warning flag for a warning mapped to an error.

For example:

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

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

Modified: cfe/trunk/include/clang/Basic/Diagnostic.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Diagnostic.h?rev=126466&r1=126465&r2=126466&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/Diagnostic.h (original)
+++ cfe/trunk/include/clang/Basic/Diagnostic.h Thu Feb 24 19:28:26 2011
@@ -474,8 +474,9 @@
   ///
   /// \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

Modified: cfe/trunk/include/clang/Basic/DiagnosticIDs.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticIDs.h?rev=126466&r1=126465&r2=126466&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticIDs.h (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticIDs.h Thu Feb 24 19:28:26 2011
@@ -188,14 +188,16 @@
   /// \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.

Modified: cfe/trunk/lib/Basic/DiagnosticIDs.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/DiagnosticIDs.cpp?rev=126466&r1=126465&r2=126466&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/DiagnosticIDs.cpp (original)
+++ cfe/trunk/lib/Basic/DiagnosticIDs.cpp Thu Feb 24 19:28:26 2011
@@ -288,14 +288,15 @@
 /// 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::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 @@
     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!");

Modified: cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp?rev=126466&r1=126465&r2=126466&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp (original)
+++ cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp Thu Feb 24 19:28:26 2011
@@ -905,9 +905,21 @@
 
   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=";

Modified: cfe/trunk/test/Sema/parentheses.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/parentheses.c?rev=126466&r1=126465&r2=126466&view=diff
==============================================================================
--- cfe/trunk/test/Sema/parentheses.c (original)
+++ cfe/trunk/test/Sema/parentheses.c Thu Feb 24 19:28:26 2011
@@ -37,3 +37,7 @@
   (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]
+





More information about the cfe-commits mailing list