[cfe-commits] r39423 - /cfe/cfe/trunk/Driver/clang.cpp

clattner at cs.uiuc.edu clattner at cs.uiuc.edu
Wed Jul 11 09:44:12 PDT 2007


Author: clattner
Date: Wed Jul 11 11:44:12 2007
New Revision: 39423

URL: http://llvm.org/viewvc/llvm-project?rev=39423&view=rev
Log:
Teach the driver to filter out warnings and notes that come from system headers.

Switch -pedantic back on by default.

Modified:
    cfe/cfe/trunk/Driver/clang.cpp

Modified: cfe/cfe/trunk/Driver/clang.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Driver/clang.cpp?rev=39423&r1=39422&r2=39423&view=diff

==============================================================================
--- cfe/cfe/trunk/Driver/clang.cpp (original)
+++ cfe/cfe/trunk/Driver/clang.cpp Wed Jul 11 11:44:12 2007
@@ -299,7 +299,7 @@
 WarningsAsErrors("Werror", cl::desc("Treat all warnings as errors"));
 
 static cl::opt<bool>
-WarnOnExtensions("pedantic", cl::init(false),
+WarnOnExtensions("pedantic", cl::init(true),
                  cl::desc("Issue a warning on uses of GCC extensions"));
 
 static cl::opt<bool>
@@ -336,10 +336,13 @@
 class DiagnosticPrinterSTDERR : public DiagnosticClient {
   SourceManager &SourceMgr;
   SourceLocation LastWarningLoc;
+  HeaderSearch *TheHeaderSearch;
 public:
   DiagnosticPrinterSTDERR(SourceManager &sourceMgr)
     : SourceMgr(sourceMgr) {}
   
+  void setHeaderSearch(HeaderSearch &HS) { TheHeaderSearch = &HS; }
+  
   void PrintIncludeStack(SourceLocation Pos);
 
   virtual void HandleDiagnostic(Diagnostic::Level DiagLevel,
@@ -367,7 +370,6 @@
                                                SourceLocation Pos,
                                                diag::kind ID, 
                                                const std::string &Extra) {
-  ++NumDiagnostics;
   unsigned LineNo = 0, FilePos = 0, FileID = 0, ColNo = 0;
   unsigned LineStart = 0, LineEnd = 0;
   const SourceBuffer *Buffer = 0;
@@ -376,6 +378,18 @@
     LineNo = SourceMgr.getLineNumber(Pos);
     FileID  = SourceMgr.getLogicalLoc(Pos).getFileID();
     
+    // If this is a warning or note, and if it a system header, suppress the
+    // diagnostic.
+    if (Level == Diagnostic::Warning ||
+        Level == Diagnostic::Note) {
+      SourceLocation PhysLoc = SourceMgr.getPhysicalLoc(Pos);
+      const FileEntry *F = SourceMgr.getFileEntryForFileID(PhysLoc.getFileID());
+      DirectoryLookup::DirType DirInfo = TheHeaderSearch->getFileDirFlavor(F);
+      if (DirInfo == DirectoryLookup::SystemHeaderDir ||
+          DirInfo == DirectoryLookup::ExternCSystemHeaderDir)
+        return;
+    }
+    
     // First, if this diagnostic is not in the main file, print out the
     // "included from" lines.
     if (LastWarningLoc != SourceMgr.getIncludeLoc(FileID)) {
@@ -446,6 +460,8 @@
     // Print out the caret itself.
     std::cerr << Indent << "^\n";
   }
+  
+  ++NumDiagnostics;
 }
 
 
@@ -1057,6 +1073,7 @@
   
   // Process the -I options and set them in the HeaderInfo.
   HeaderSearch HeaderInfo(FileMgr);
+  OurDiagnosticClient.setHeaderSearch(HeaderInfo);
   InitializeIncludePaths(HeaderInfo, FileMgr, Diags, LangInfo);
   
   for (unsigned i = 0, e = InputFilenames.size(); i != e; ++i)





More information about the cfe-commits mailing list