aboutsummaryrefslogtreecommitdiff
path: root/libcpp/init.c
diff options
context:
space:
mode:
authorNathan Sidwell <nathan@acm.org>2020-11-06 08:53:31 -0800
committerNathan Sidwell <nathan@acm.org>2020-11-06 08:59:20 -0800
commit4b5f564a5d958295d51a1a7ff825896a89f22b75 (patch)
tree89b054bb02f70619eacc29089f28e45e102c1a27 /libcpp/init.c
parent6c3ce63b04b38f84c0357e4648383f0e3ab11cd9 (diff)
downloadgcc-4b5f564a5d958295d51a1a7ff825896a89f22b75.zip
gcc-4b5f564a5d958295d51a1a7ff825896a89f22b75.tar.gz
gcc-4b5f564a5d958295d51a1a7ff825896a89f22b75.tar.bz2
libcpp: Provide date routine
Joseph pointed me at cb_get_source_date_epoch, which allows repeatable builds and solves a FIXME I had on the modules branch. Unfortunately it's used exclusively to generate __DATE__ and __TIME__ values, which fallback to using a time(2) call. It'd be nicer if the preprocessor made whatever time value it determined available to the rest of the compiler. So this patch adds a new cpp_get_date function, which abstracts the call to the get_source_date_epoch hook, or uses time directly. The value is cached. Thus the timestamp I end up putting on CMI files matches __DATE__ and __TIME__ expansions. That seems worthwhile. libcpp/ * include/cpplib.h (enum class CPP_time_kind): New. (cpp_get_date): Declare. * internal.h (struct cpp_reader): Replace source_date_epoch with time_stamp and time_stamp_kind. * init.c (cpp_create_reader): Initialize them. * macro.c (_cpp_builtin_macro_text): Use cpp_get_date. (cpp_get_date): Broken out from _cpp_builtin_macro_text and genericized.
Diffstat (limited to 'libcpp/init.c')
-rw-r--r--libcpp/init.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/libcpp/init.c b/libcpp/init.c
index 6c52f50..dcf1d4b 100644
--- a/libcpp/init.c
+++ b/libcpp/init.c
@@ -273,8 +273,9 @@ cpp_create_reader (enum c_lang lang, cpp_hash_table *table,
/* Do not force token locations by default. */
pfile->forced_token_location = 0;
- /* Initialize source_date_epoch to -2 (not yet set). */
- pfile->source_date_epoch = (time_t) -2;
+ /* Note the timestamp is unset. */
+ pfile->time_stamp = time_t (-1);
+ pfile->time_stamp_kind = 0;
/* The expression parser stack. */
_cpp_expand_op_stack (pfile);