r210512 - Show -Wdate-time in system headers
Alp Toker
alp at nuanti.com
Mon Jun 9 23:09:00 PDT 2014
Author: alp
Date: Tue Jun 10 01:09:00 2014
New Revision: 210512
URL: http://llvm.org/viewvc/llvm-project?rev=210512&view=rev
Log:
Show -Wdate-time in system headers
Anyone enabling this warning would expect to hear about all occurrences
including those in system headers that can cause non-reproducible builds.
To achieve this, rework ShowInSystemHeader to remove broken unused mapping code
that didn't make sense with a simpler and correct scheme.
Modified:
cfe/trunk/include/clang/Basic/DiagnosticIDs.h
cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td
cfe/trunk/lib/Basic/DiagnosticIDs.cpp
cfe/trunk/test/Lexer/warn-date-time.c
Modified: cfe/trunk/include/clang/Basic/DiagnosticIDs.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticIDs.h?rev=210512&r1=210511&r2=210512&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticIDs.h (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticIDs.h Tue Jun 10 01:09:00 2014
@@ -74,7 +74,6 @@ class DiagnosticMappingInfo {
unsigned Mapping : 3;
unsigned IsUser : 1;
unsigned IsPragma : 1;
- unsigned HasShowInSystemHeader : 1;
unsigned HasNoWarningAsError : 1;
unsigned HasNoErrorAsFatal : 1;
@@ -85,7 +84,6 @@ public:
Result.Mapping = Mapping;
Result.IsUser = IsUser;
Result.IsPragma = IsPragma;
- Result.HasShowInSystemHeader = 0;
Result.HasNoWarningAsError = 0;
Result.HasNoErrorAsFatal = 0;
return Result;
@@ -97,9 +95,6 @@ public:
bool isUser() const { return IsUser; }
bool isPragma() const { return IsPragma; }
- bool hasShowInSystemHeader() const { return HasShowInSystemHeader; }
- void setShowInSystemHeader(bool Value) { HasShowInSystemHeader = Value; }
-
bool hasNoWarningAsError() const { return HasNoWarningAsError; }
void setNoWarningAsError(bool Value) { HasNoWarningAsError = Value; }
Modified: cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td?rev=210512&r1=210511&r2=210512&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td Tue Jun 10 01:09:00 2014
@@ -544,7 +544,7 @@ def err_pp_eof_in_arc_cf_code_audited :
def warn_pp_date_time : Warning<
"expansion of date or time macro is not reproducible">,
- DefaultIgnore, InGroup<DiagGroup<"date-time">>;
+ DefaultWarnShowInSystemHeader, DefaultIgnore, InGroup<DiagGroup<"date-time">>;
// Module map parsing
def err_mmap_unknown_token : Error<"skipping stray token">;
Modified: cfe/trunk/lib/Basic/DiagnosticIDs.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/DiagnosticIDs.cpp?rev=210512&r1=210511&r2=210512&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/DiagnosticIDs.cpp (original)
+++ cfe/trunk/lib/Basic/DiagnosticIDs.cpp Tue Jun 10 01:09:00 2014
@@ -164,12 +164,6 @@ static DiagnosticMappingInfo GetDefaultD
"Unexpected mapping with no-Werror bit!");
Info.setNoWarningAsError(true);
}
-
- if (StaticInfo->WarnShowInSystemHeader) {
- assert(Info.getMapping() == diag::MAP_WARNING &&
- "Unexpected mapping with show-in-system-header bit!");
- Info.setShowInSystemHeader(true);
- }
}
return Info;
@@ -486,16 +480,15 @@ DiagnosticIDs::getDiagnosticLevel(unsign
Result = DiagnosticIDs::Fatal;
}
+ // Custom diagnostics always are emitted in system headers.
+ bool ShowInSystemHeader =
+ !GetDiagInfo(DiagID) || GetDiagInfo(DiagID)->WarnShowInSystemHeader;
+
// If we are in a system header, we ignore it. We look at the diagnostic class
// because we also want to ignore extensions and warnings in -Werror and
// -pedantic-errors modes, which *map* warnings/extensions to errors.
- if (Result >= DiagnosticIDs::Warning &&
- DiagClass != CLASS_ERROR &&
- // Custom diagnostics always are emitted in system headers.
- DiagID < diag::DIAG_UPPER_LIMIT &&
- !MappingInfo.hasShowInSystemHeader() &&
- Diag.SuppressSystemWarnings &&
- Loc.isValid() &&
+ if (Result >= DiagnosticIDs::Warning && DiagClass != CLASS_ERROR &&
+ !ShowInSystemHeader && Diag.SuppressSystemWarnings && Loc.isValid() &&
Diag.getSourceManager().isInSystemHeader(
Diag.getSourceManager().getExpansionLoc(Loc)))
return DiagnosticIDs::Ignored;
Modified: cfe/trunk/test/Lexer/warn-date-time.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Lexer/warn-date-time.c?rev=210512&r1=210511&r2=210512&view=diff
==============================================================================
--- cfe/trunk/test/Lexer/warn-date-time.c (original)
+++ cfe/trunk/test/Lexer/warn-date-time.c Tue Jun 10 01:09:00 2014
@@ -1,4 +1,13 @@
// RUN: %clang_cc1 -Wdate-time -Wno-builtin-macro-redefined %s -verify -E
+// RUN: %clang_cc1 -Wdate-time -Wno-builtin-macro-redefined %s -DIS_SYSHEADER -verify -E
+// RUN: not %clang_cc1 -Werror=date-time -Wno-builtin-macro-redefined %s -DIS_SYSHEADER -E 2>&1 | grep 'error: expansion' | count 3
+
+
+#ifdef IS_HEADER
+
+#ifdef IS_SYSHEADER
+#pragma clang system_header
+#endif
__TIME__ // expected-warning {{expansion of date or time macro is not reproducible}}
__DATE__ // expected-warning {{expansion of date or time macro is not reproducible}}
@@ -6,3 +15,9 @@ __TIMESTAMP__ // expected-warning {{expa
#define __TIME__
__TIME__
+
+#else
+
+#define IS_HEADER
+#include __FILE__
+#endif
More information about the cfe-commits
mailing list