[cfe-commits] r56163 - in /cfe/trunk: Driver/clang.cpp include/clang/Basic/Diagnostic.h lib/Basic/Diagnostic.cpp lib/Sema/SemaDecl.cpp
Daniel Dunbar
daniel at zuster.org
Fri Sep 12 11:10:20 PDT 2008
Author: ddunbar
Date: Fri Sep 12 13:10:20 2008
New Revision: 56163
URL: http://llvm.org/viewvc/llvm-project?rev=56163&view=rev
Log:
Add --suppress-system-warnings (on by default, use =0 to disable)
- 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).
Modified:
cfe/trunk/Driver/clang.cpp
cfe/trunk/include/clang/Basic/Diagnostic.h
cfe/trunk/lib/Basic/Diagnostic.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
Modified: cfe/trunk/Driver/clang.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/clang.cpp?rev=56163&r1=56162&r2=56163&view=diff
==============================================================================
--- cfe/trunk/Driver/clang.cpp (original)
+++ cfe/trunk/Driver/clang.cpp Fri Sep 12 13:10:20 2008
@@ -520,6 +520,11 @@
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 @@
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);
Modified: cfe/trunk/include/clang/Basic/Diagnostic.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Diagnostic.h?rev=56163&r1=56162&r2=56163&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/Diagnostic.h (original)
+++ cfe/trunk/include/clang/Basic/Diagnostic.h Fri Sep 12 13:10:20 2008
@@ -61,6 +61,7 @@
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 @@
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) {
Modified: cfe/trunk/lib/Basic/Diagnostic.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Diagnostic.cpp?rev=56163&r1=56162&r2=56163&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/Diagnostic.cpp (original)
+++ cfe/trunk/lib/Basic/Diagnostic.cpp Fri Sep 12 13:10:20 2008
@@ -113,6 +113,7 @@
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 @@
// 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;
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=56163&r1=56162&r2=56163&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Fri Sep 12 13:10:20 2008
@@ -276,11 +276,13 @@
// *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);
More information about the cfe-commits
mailing list