libcpp: Provide date routine

Nathan Sidwell
Fri Nov 6 16:58:22 GMT 2020

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

         * include/libcpp.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

pushing to trunk


Nathan Sidwell
-------------- next part --------------
A non-text attachment was scrubbed...
Name: date-stamp.diff
Type: text/x-patch
Size: 5641 bytes
Desc: not available
URL: <>

More information about the Gcc-patches mailing list