]> granicus.if.org Git - clang/commitdiff
Move the check whether a diagnostic must be ignored because it is in a system header
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Thu, 21 Apr 2011 23:08:18 +0000 (23:08 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Thu, 21 Apr 2011 23:08:18 +0000 (23:08 +0000)
inside DiagnosticIDs::getDiagnosticLevel.

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

lib/Basic/DiagnosticIDs.cpp

index 68f630d0b1f84c13cc082bf36cb8918855d64308..f92a34edd2653505e995635cb640b4e9e952773b 100644 (file)
@@ -470,6 +470,19 @@ DiagnosticIDs::getDiagnosticLevel(unsigned DiagID, unsigned DiagClass,
   if (Diag.AllExtensionsSilenced && isBuiltinExtensionDiag(DiagID))
     return DiagnosticIDs::Ignored;
 
+  // If we are in a system header, we ignore it.
+  // We also want to ignore extensions and warnings in -Werror and
+  // -pedantic-errors modes, which *map* warnings/extensions to errors.
+  if (Result >= DiagnosticIDs::Warning &&
+      DiagClass != CLASS_ERROR &&
+      // Custom diagnostics always are emitted in system headers.
+      DiagID < diag::DIAG_UPPER_LIMIT &&
+      Diag.SuppressSystemWarnings &&
+      Loc.isValid() &&
+      Diag.getSourceManager().isInSystemHeader(
+          Diag.getSourceManager().getInstantiationLoc(Loc)))
+    return DiagnosticIDs::Ignored;
+
   return Result;
 }
 
@@ -555,16 +568,9 @@ bool DiagnosticIDs::ProcessDiag(Diagnostic &Diag) const {
   DiagnosticIDs::Level DiagLevel;
   unsigned DiagID = Info.getID();
 
-  // ShouldEmitInSystemHeader - True if this diagnostic should be produced even
-  // in a system header.
-  bool ShouldEmitInSystemHeader;
-
   if (DiagID >= diag::DIAG_UPPER_LIMIT) {
     // Handle custom diagnostics, which cannot be mapped.
     DiagLevel = CustomDiagInfo->getLevel(DiagID);
-
-    // Custom diagnostics always are emitted in system headers.
-    ShouldEmitInSystemHeader = true;
   } else {
     // Get the class of the diagnostic.  If this is a NOTE, map it onto whatever
     // the diagnostic level was for the previous diagnostic so that it is
@@ -572,14 +578,7 @@ bool DiagnosticIDs::ProcessDiag(Diagnostic &Diag) const {
     unsigned DiagClass = getBuiltinDiagClass(DiagID);
     if (DiagClass == CLASS_NOTE) {
       DiagLevel = DiagnosticIDs::Note;
-      ShouldEmitInSystemHeader = false;  // extra consideration is needed
     } else {
-      // If this is not an error and we are in a system header, we ignore it.
-      // Check the original Diag ID here, because we also want to ignore
-      // extensions and warnings in -Werror and -pedantic-errors modes, which
-      // *map* warnings/extensions to errors.
-      ShouldEmitInSystemHeader = DiagClass == CLASS_ERROR;
-
       DiagLevel = getDiagnosticLevel(DiagID, DiagClass, Info.getLocation(),
                                      Diag);
     }
@@ -615,18 +614,6 @@ bool DiagnosticIDs::ProcessDiag(Diagnostic &Diag) const {
        Diag.LastDiagLevel == DiagnosticIDs::Ignored))
     return false;
 
-  // If this diagnostic is in a system header and is not a clang error, suppress
-  // it.
-  if (Diag.SuppressSystemWarnings && !ShouldEmitInSystemHeader &&
-      Info.getLocation().isValid() &&
-      Diag.getSourceManager().isInSystemHeader(
-          Diag.getSourceManager().getInstantiationLoc(Info.getLocation())) &&
-      (DiagLevel != DiagnosticIDs::Note ||
-       Diag.LastDiagLevel == DiagnosticIDs::Ignored)) {
-    Diag.LastDiagLevel = DiagnosticIDs::Ignored;
-    return false;
-  }
-
   if (DiagLevel >= DiagnosticIDs::Error) {
     if (Diag.Client->IncludeInDiagnosticCounts()) {
       Diag.ErrorOccurred = true;