[cfe-commits] r46686 - in /cfe/trunk: Basic/Diagnostic.cpp Driver/TextDiagnostics.cpp Driver/TextDiagnostics.h include/clang/Basic/Diagnostic.h

Chris Lattner sabre at nondot.org
Sun Feb 3 01:00:04 PST 2008


Author: lattner
Date: Sun Feb  3 03:00:04 2008
New Revision: 46686

URL: http://llvm.org/viewvc/llvm-project?rev=46686&view=rev
Log:
Fix PR1966 by ignoring non-error diagnostics from system headers even if they are 
*mapped* onto errors.

Modified:
    cfe/trunk/Basic/Diagnostic.cpp
    cfe/trunk/Driver/TextDiagnostics.cpp
    cfe/trunk/Driver/TextDiagnostics.h
    cfe/trunk/include/clang/Basic/Diagnostic.h

Modified: cfe/trunk/Basic/Diagnostic.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Basic/Diagnostic.cpp?rev=46686&r1=46685&r2=46686&view=diff

==============================================================================
--- cfe/trunk/Basic/Diagnostic.cpp (original)
+++ cfe/trunk/Basic/Diagnostic.cpp Sun Feb  3 03:00:04 2008
@@ -200,22 +200,28 @@
 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);

Modified: cfe/trunk/Driver/TextDiagnostics.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/TextDiagnostics.cpp?rev=46686&r1=46685&r2=46686&view=diff

==============================================================================
--- cfe/trunk/Driver/TextDiagnostics.cpp (original)
+++ cfe/trunk/Driver/TextDiagnostics.cpp Sun Feb  3 03:00:04 2008
@@ -39,19 +39,14 @@
   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;

Modified: cfe/trunk/Driver/TextDiagnostics.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/TextDiagnostics.h?rev=46686&r1=46685&r2=46686&view=diff

==============================================================================
--- cfe/trunk/Driver/TextDiagnostics.h (original)
+++ cfe/trunk/Driver/TextDiagnostics.h Sun Feb  3 03:00:04 2008
@@ -34,8 +34,7 @@
 
   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,

Modified: cfe/trunk/include/clang/Basic/Diagnostic.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Diagnostic.h?rev=46686&r1=46685&r2=46686&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/Diagnostic.h (original)
+++ cfe/trunk/include/clang/Basic/Diagnostic.h Sun Feb  3 03:00:04 2008
@@ -166,10 +166,9 @@
 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.





More information about the cfe-commits mailing list