r210511 - Implement -Wdate-time preprocessor warning
Alp Toker
alp at nuanti.com
Mon Jun 9 23:08:51 PDT 2014
Author: alp
Date: Tue Jun 10 01:08:51 2014
New Revision: 210511
URL: http://llvm.org/viewvc/llvm-project?rev=210511&view=rev
Log:
Implement -Wdate-time preprocessor warning
This GCC warning is useful for validating reproducible builds
and might help when tracking down issues with modules too.
Added:
cfe/trunk/test/Lexer/warn-date-time.c
Modified:
cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td
cfe/trunk/lib/Lex/PPMacroExpansion.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td?rev=210511&r1=210510&r2=210511&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td Tue Jun 10 01:08:51 2014
@@ -542,6 +542,10 @@ def err_pp_include_in_arc_cf_code_audite
def err_pp_eof_in_arc_cf_code_audited : Error<
"'#pragma clang arc_cf_code_audited' was not ended within this file">;
+def warn_pp_date_time : Warning<
+ "expansion of date or time macro is not reproducible">,
+ DefaultIgnore, InGroup<DiagGroup<"date-time">>;
+
// Module map parsing
def err_mmap_unknown_token : Error<"skipping stray token">;
def err_mmap_expected_module : Error<"expected module declaration">;
Modified: cfe/trunk/lib/Lex/PPMacroExpansion.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPMacroExpansion.cpp?rev=210511&r1=210510&r2=210511&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PPMacroExpansion.cpp (original)
+++ cfe/trunk/lib/Lex/PPMacroExpansion.cpp Tue Jun 10 01:08:51 2014
@@ -1294,6 +1294,7 @@ void Preprocessor::ExpandBuiltinMacro(To
}
Tok.setKind(tok::string_literal);
} else if (II == Ident__DATE__) {
+ Diag(Tok.getLocation(), diag::warn_pp_date_time);
if (!DATELoc.isValid())
ComputeDATE_TIME(DATELoc, TIMELoc, *this);
Tok.setKind(tok::string_literal);
@@ -1303,6 +1304,7 @@ void Preprocessor::ExpandBuiltinMacro(To
Tok.getLength()));
return;
} else if (II == Ident__TIME__) {
+ Diag(Tok.getLocation(), diag::warn_pp_date_time);
if (!TIMELoc.isValid())
ComputeDATE_TIME(DATELoc, TIMELoc, *this);
Tok.setKind(tok::string_literal);
@@ -1327,6 +1329,7 @@ void Preprocessor::ExpandBuiltinMacro(To
OS << Depth;
Tok.setKind(tok::numeric_constant);
} else if (II == Ident__TIMESTAMP__) {
+ Diag(Tok.getLocation(), diag::warn_pp_date_time);
// MSVC, ICC, GCC, VisualAge C++ extension. The generated string should be
// of the form "Ddd Mmm dd hh::mm::ss yyyy", which is returned by asctime.
@@ -1347,7 +1350,7 @@ void Preprocessor::ExpandBuiltinMacro(To
Result = "??? ??? ?? ??:??:?? ????\n";
}
// Surround the string with " and strip the trailing newline.
- OS << '"' << StringRef(Result, strlen(Result)-1) << '"';
+ OS << '"' << StringRef(Result).drop_back() << '"';
Tok.setKind(tok::string_literal);
} else if (II == Ident__COUNTER__) {
// __COUNTER__ expands to a simple numeric value.
Added: cfe/trunk/test/Lexer/warn-date-time.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Lexer/warn-date-time.c?rev=210511&view=auto
==============================================================================
--- cfe/trunk/test/Lexer/warn-date-time.c (added)
+++ cfe/trunk/test/Lexer/warn-date-time.c Tue Jun 10 01:08:51 2014
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -Wdate-time -Wno-builtin-macro-redefined %s -verify -E
+
+__TIME__ // expected-warning {{expansion of date or time macro is not reproducible}}
+__DATE__ // expected-warning {{expansion of date or time macro is not reproducible}}
+__TIMESTAMP__ // expected-warning {{expansion of date or time macro is not reproducible}}
+
+#define __TIME__
+__TIME__
More information about the cfe-commits
mailing list