]> granicus.if.org Git - clang/commitdiff
Add --suppress-system-warnings (on by default, use =0 to disable)
authorDaniel Dunbar <daniel@zuster.org>
Fri, 12 Sep 2008 18:10:20 +0000 (18:10 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Fri, 12 Sep 2008 18:10:20 +0000 (18:10 +0000)
 - For investigating warnings in system headers / builtins.
 - Currently also enables the behavior that allows silent redefinition
   of types in system headers. Conceptually these are separate but I
   didn't feel it was worth two options (or changing LangOptions).

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

Driver/clang.cpp
include/clang/Basic/Diagnostic.h
lib/Basic/Diagnostic.cpp
lib/Sema/SemaDecl.cpp

index ef12eaf2c263d79369c59d7dee72a9c1b1a637ef..0efe56a35073c58855819c5aed73f446d265b236 100644 (file)
@@ -519,6 +519,11 @@ static llvm::cl::opt<bool>
 ErrorOnExtensions("pedantic-errors",
                   llvm::cl::desc("Issue an error on uses of GCC extensions"));
 
+static llvm::cl::opt<bool>
+SuppressSystemWarnings("suppress-system-warnings",
+                     llvm::cl::desc("Issue an error on uses of GCC extensions"),
+                       llvm::cl::init(true));
+
 static llvm::cl::opt<bool>
 WarnUnusedMacros("Wunused_macros",
          llvm::cl::desc("Warn for unused macros in the main translation unit"));
@@ -547,6 +552,9 @@ static void InitializeDiagnostics(Diagnostic &Diags) {
   Diags.setWarnOnExtensions(WarnOnExtensions);
   Diags.setErrorOnExtensions(ErrorOnExtensions);
 
+  // Suppress warnings in system headers unless requested not to.
+  Diags.setSuppressSystemWarnings(SuppressSystemWarnings);
+
   // Silence the "macro is not used" warning unless requested.
   if (!WarnUnusedMacros)
     Diags.setDiagnosticMapping(diag::pp_macro_not_used, diag::MAP_IGNORE);
index c23abdcd0fe8779754499c422a829700271192c4..8b0637f59ee2d9afd73bcd01eee7b191f2b83df4 100644 (file)
@@ -61,6 +61,7 @@ private:
   bool WarningsAsErrors;      // Treat warnings like errors: 
   bool WarnOnExtensions;      // Enables warnings for gcc extensions: -pedantic.
   bool ErrorOnExtensions;     // Error on extensions: -pedantic-errors.
+  bool SuppressSystemWarnings;// Suppress warnings in system headers.
   DiagnosticClient *Client;
 
   /// DiagMappings - Mapping information for diagnostics.  Mapping info is
@@ -110,6 +111,11 @@ public:
   void setErrorOnExtensions(bool Val) { ErrorOnExtensions = Val; }
   bool getErrorOnExtensions() const { return ErrorOnExtensions; }
 
+  /// setSuppressSystemWarnings - When set to true mask warnings that
+  /// come from system headers.
+  void setSuppressSystemWarnings(bool Val) { SuppressSystemWarnings = Val; }
+  bool getSuppressSystemWarnings() const { return SuppressSystemWarnings; }
+
   /// setDiagnosticMapping - This allows the client to specify that certain
   /// warnings are ignored.  Only NOTEs, WARNINGs, and EXTENSIONs can be mapped.
   void setDiagnosticMapping(diag::kind Diag, diag::Mapping Map) {
index f9e1d2bda3ea3ea42f557d20c51af0285f04126c..0f8f314f15c8a700185511627de72c73026da8b0 100644 (file)
@@ -113,6 +113,7 @@ Diagnostic::Diagnostic(DiagnosticClient *client) : Client(client) {
   WarningsAsErrors = false;
   WarnOnExtensions = false;
   ErrorOnExtensions = false;
+  SuppressSystemWarnings = false;
   // Clear all mappings, setting them to MAP_DEFAULT.
   memset(DiagMappings, 0, sizeof(DiagMappings));
   
@@ -224,7 +225,8 @@ void Diagnostic::Report(DiagnosticClient* C,
   // have to check on the original DiagID 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 &&
+  if (SuppressSystemWarnings &&
+      DiagID < diag::NUM_BUILTIN_DIAGNOSTICS &&
       getBuiltinDiagClass(DiagID) != ERROR &&
       Loc.isValid() && Loc.isFileID() && Loc.isInSystemHeader())
     return;
index 726372356e514cc9a3d3ced7b075dbfafd2b66d1..2f4350766ac9e0619ebb634d38bbe7d8469604b1 100644 (file)
@@ -276,11 +276,13 @@ TypedefDecl *Sema::MergeTypeDefDecl(TypedefDecl *New, Decl *OldD) {
   // *either* declaration is in a system header. The code below implements
   // this adhoc compatibility rule. FIXME: The following code will not
   // work properly when compiling ".i" files (containing preprocessed output).
-  SourceManager &SrcMgr = Context.getSourceManager();
-  if (SrcMgr.isInSystemHeader(Old->getLocation()))
-    return New;
-  if (SrcMgr.isInSystemHeader(New->getLocation()))
-    return New;
+  if (PP.getDiagnostics().getSuppressSystemWarnings()) {
+    SourceManager &SrcMgr = Context.getSourceManager();
+    if (SrcMgr.isInSystemHeader(Old->getLocation()))
+      return New;
+    if (SrcMgr.isInSystemHeader(New->getLocation()))
+      return New;
+  }
 
   Diag(New->getLocation(), diag::err_redefinition, New->getName());
   Diag(Old->getLocation(), diag::err_previous_definition);