]> granicus.if.org Git - clang/commitdiff
Fix PR1966 by ignoring non-error diagnostics from system headers even if they are
authorChris Lattner <sabre@nondot.org>
Sun, 3 Feb 2008 09:00:04 +0000 (09:00 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 3 Feb 2008 09:00:04 +0000 (09:00 +0000)
*mapped* onto errors.

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

Basic/Diagnostic.cpp
Driver/TextDiagnostics.cpp
Driver/TextDiagnostics.h
include/clang/Basic/Diagnostic.h

index 158e8ff33f48a8b5602c7d7815e7ed0c7a5fcf4b..de311a448809ac3b5a4e207e4e27c8385f55145d 100644 (file)
@@ -200,22 +200,28 @@ Diagnostic::Level Diagnostic::getDiagnosticLevel(unsigned DiagID) const {
 void Diagnostic::Report(FullSourceLoc Pos, unsigned DiagID,
                         const std::string *Strs, unsigned NumStrs,
                         const SourceRange *Ranges, unsigned NumRanges) {
+  
   // Figure out the diagnostic level of this message.
   Diagnostic::Level DiagLevel = getDiagnosticLevel(DiagID);
   
   // If the client doesn't care about this message, don't issue it.
   if (DiagLevel == Diagnostic::Ignored)
     return;
+
+  // If this is not an error and we are in a system header, ignore it.  We have
+  // to check on the original class here, because we also want to ignore
+  // extensions and warnings in -Werror and -pedantic-errors modes, which *map*
+  // warnings/extensions to errors.
+  if (DiagID < diag::NUM_BUILTIN_DIAGNOSTICS &&
+      getBuiltinDiagClass(DiagID) != ERROR &&
+      Client.isInSystemHeader(Pos))
+    return;
   
   if (DiagLevel >= Diagnostic::Error) {
     ErrorOccurred = true;
     ++NumErrors;
   }
 
-  // Are we going to ignore this diagnosic?
-  if (Client.IgnoreDiagnostic(DiagLevel, Pos))
-    return;
-
   // Finally, report it.
   Client.HandleDiagnostic(*this, DiagLevel, Pos, (diag::kind)DiagID,
                           Strs, NumStrs, Ranges, NumRanges);
index 01484e0fc497c372468ba68d06aa8052a60680a5..7a78e9478331ea55be68d8aae085a612682a3eb6 100644 (file)
@@ -39,19 +39,14 @@ std::string TextDiagnostics::FormatDiagnostic(Diagnostic &Diags,
   return Msg;
 }
 
-bool TextDiagnostics::IgnoreDiagnostic(Diagnostic::Level Level,
-                                       FullSourceLoc Pos) {
-  if (Pos.isValid()) {
-    // If this is a warning or note, and if it a system header, suppress the
-    // diagnostic.
-    if (Level == Diagnostic::Warning || Level == Diagnostic::Note) {
-      if (const FileEntry *F = Pos.getFileEntryForLoc()) {
-        DirectoryLookup::DirType DirInfo = TheHeaderSearch->getFileDirFlavor(F);
-        if (DirInfo == DirectoryLookup::SystemHeaderDir ||
-            DirInfo == DirectoryLookup::ExternCSystemHeaderDir)
-          return true;
-      }
-    }
+bool TextDiagnostics::isInSystemHeader(FullSourceLoc Pos) const {
+  if (!Pos.isValid()) return false;
+  
+  if (const FileEntry *F = Pos.getFileEntryForLoc()) {
+    DirectoryLookup::DirType DirInfo = TheHeaderSearch->getFileDirFlavor(F);
+    if (DirInfo == DirectoryLookup::SystemHeaderDir ||
+        DirInfo == DirectoryLookup::ExternCSystemHeaderDir)
+      return true;
   }
 
   return false;
index 82ea11661f05849625163b856ad194bde0e173fc..9b8d9fb27db956a769f4587647a1b7823f09e261 100644 (file)
@@ -34,8 +34,7 @@ public:
 
   void setHeaderSearch(HeaderSearch &HS) { TheHeaderSearch = &HS; }
 
-  virtual bool IgnoreDiagnostic(Diagnostic::Level Level, 
-                                FullSourceLoc Pos);
+  virtual bool isInSystemHeader(FullSourceLoc Pos) const;
 
   virtual void HandleDiagnostic(Diagnostic &Diags, Diagnostic::Level DiagLevel,
                                 FullSourceLoc Pos,
index 9f18de305eeb6dbae9682cb1c7c85d9adfbac76d..35a326609313d818033e3955fc9de0ac39cbd0e3 100644 (file)
@@ -166,10 +166,9 @@ class DiagnosticClient {
 public:
   virtual ~DiagnosticClient();
 
-  /// IgnoreDiagnostic - If the client wants to ignore this diagnostic, then
+  /// isInSystemHeader - If the client can tell that this is a system header,
   /// return true.
-  virtual bool IgnoreDiagnostic(Diagnostic::Level DiagLevel,
-                                FullSourceLoc Pos) = 0;
+  virtual bool isInSystemHeader(FullSourceLoc Pos) const { return false; }
 
   /// HandleDiagnostic - Handle this diagnostic, reporting it to the user or
   /// capturing it to a log as needed.