]> granicus.if.org Git - clang/commitdiff
fix PR6814 - Only print [-pedantic] on a diagnostic if -pedantic
authorChris Lattner <sabre@nondot.org>
Mon, 12 Apr 2010 21:53:11 +0000 (21:53 +0000)
committerChris Lattner <sabre@nondot.org>
Mon, 12 Apr 2010 21:53:11 +0000 (21:53 +0000)
actually turned it on.  If a diag is produced by a warning which
is an extension but defaults to on, and has no warning group, don't
print any option info.

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

include/clang/Basic/Diagnostic.h
lib/Basic/Diagnostic.cpp
lib/Frontend/TextDiagnosticPrinter.cpp

index e088965996052e7033fe384b5be9fd991d7a32eb..8c959b7cea23c635f4ec24b07f3207db0dfa300f 100644 (file)
@@ -388,7 +388,18 @@ public:
   /// isBuiltinExtensionDiag - Determine whether the given built-in diagnostic
   /// ID is for an extension of some sort.
   ///
-  static bool isBuiltinExtensionDiag(unsigned DiagID);
+  static bool isBuiltinExtensionDiag(unsigned DiagID) {
+    bool ignored;
+    return isBuiltinExtensionDiag(DiagID, ignored);
+  }
+  
+  /// isBuiltinExtensionDiag - Determine whether the given built-in diagnostic
+  /// ID is for an extension of some sort.  This also returns EnabledByDefault,
+  /// which is set to indicate whether the diagnostic is ignored by default (in
+  /// which case -pedantic enables it) or treated as a warning/error by default.
+  ///
+  static bool isBuiltinExtensionDiag(unsigned DiagID, bool &EnabledByDefault);
+  
 
   /// getWarningOptionForDiag - Return the lowest-level warning option that
   /// enables the specified diagnostic.  If there is no -Wfoo flag that controls
@@ -478,7 +489,7 @@ private:
   /// getDiagnosticMappingInfo - Return the mapping info currently set for the
   /// specified builtin diagnostic.  This returns the high bit encoding, or zero
   /// if the field is completely uninitialized.
-  unsigned getDiagnosticMappingInfo(diag::kind Diag) const {
+  diag::Mapping getDiagnosticMappingInfo(diag::kind Diag) const {
     const DiagMappings &currentMappings = DiagMappingsStack.back();
     return (diag::Mapping)((currentMappings[Diag/2] >> (Diag & 1)*4) & 15);
   }
index 1eeb25b877033a78407e0d3d51abaf0c78f2c7c9..bd1d6e8b70e9efaa2ce26ddb8cda143d26d44239 100644 (file)
@@ -287,11 +287,18 @@ bool Diagnostic::isBuiltinNote(unsigned DiagID) {
 }
 
 /// isBuiltinExtensionDiag - Determine whether the given built-in diagnostic
-/// ID is for an extension of some sort.
+/// ID is for an extension of some sort.  This also returns EnabledByDefault,
+/// which is set to indicate whether the diagnostic is ignored by default (in
+/// which case -pedantic enables it) or treated as a warning/error by default.
 ///
-bool Diagnostic::isBuiltinExtensionDiag(unsigned DiagID) {
-  return DiagID < diag::DIAG_UPPER_LIMIT &&
-         getBuiltinDiagClass(DiagID) == CLASS_EXTENSION;
+bool Diagnostic::isBuiltinExtensionDiag(unsigned DiagID,
+                                        bool &EnabledByDefault) {
+  if (DiagID >= diag::DIAG_UPPER_LIMIT ||
+      getBuiltinDiagClass(DiagID) != CLASS_EXTENSION)
+    return false;
+  
+  EnabledByDefault = StaticDiagInfo[DiagID].Mapping != diag::MAP_IGNORE;
+  return true;
 }
 
 
index 4e91f8d4c221f0e8e238f837c271c3d3d1e9d3e0..6c8137e3d29b3a022eb849f054c8b0f930fcea14 100644 (file)
@@ -796,8 +796,13 @@ void TextDiagnosticPrinter::HandleDiagnostic(Diagnostic::Level Level,
       OutStr += " [-W";
       OutStr += Opt;
       OutStr += ']';
-    } else if (Diagnostic::isBuiltinExtensionDiag(Info.getID())) {
-      OutStr += " [-pedantic]";
+    } else {
+      // If the diagnostic is an extension diagnostic and not enabled by default
+      // then it must have been turned on with -pedantic.
+      bool EnabledByDefault;
+      if (Diagnostic::isBuiltinExtensionDiag(Info.getID(), EnabledByDefault) &&
+          !EnabledByDefault)
+        OutStr += " [-pedantic]";
     }
   }