This is an archive of the discontinued LLVM Phabricator instance.

Rebase D23934: Add a -ffixed-date-time= flag that sets the initial value of __DATE__, __TIME__, __TIMESTAMP__
Needs ReviewPublic

Authored by appcs on Mar 25 2022, 4:29 PM.

Details

Summary

[Preprocessor] Add a -ffixed-date-time= flag that sets the initial value of DATE, TIME, TIMESTAMP

Rebase D23934.

Diff Detail

Event Timeline

appcs created this revision.Mar 25 2022, 4:29 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 25 2022, 4:29 PM
appcs requested review of this revision.Mar 25 2022, 4:29 PM
appcs added a comment.Mar 25 2022, 4:36 PM

(From D121040) Please let me know about the following and I will incorporate your feedback and submit subsequent patches for addressing these questions:

a. Disallow the simultaneous use of -Wdate-time/-Wpch-date-time and -ffixed-date-time=<timestamp>?
b. Disallow -ffixed-date-time=<timestamp>:

0. if PCH's are used
1. in PCH compilation

Also, (just as -Wdate-time warns on TIMESTAMP use), do we (in a separate patch), extend the scope of -Wpch-date-time to cover the use of TIMESTAMP is in a PCH?

Thank you.

MaskRay added a comment.EditedMar 25 2022, 4:47 PM

Bazel uses -Wno-builtin-macro-redefined -D__DATE__="redacted" -D__TIMESTAMP__="redacted" -D__TIME__="redacted".
For reproducibility purposes, this is sufficient. I have two questions:

  • Do we need the arbitrary time feature?
  • Should an arbitrary string like "redacted" be supported?
appcs added a comment.Mar 28 2022, 2:15 PM

Bazel uses -Wno-builtin-macro-redefined -D__DATE__="redacted" -D__TIMESTAMP__="redacted" -D__TIME__="redacted".
For reproducibility purposes, this is sufficient. I have two questions:

  • Do we need the arbitrary time feature?

If you are saying that defining DATE, TIMESTAMP, TIME to an arbitrary time value, then that is the definition of the problem that we are trying to solve; else, please clarify. Thanks.

  • Should an arbitrary string like "redacted" be supported?

Via -ffixed-date-time the value would have to be formatted e.g. 1969-12-31T23:59:59 (RFC3339 without fractional seconds and timezone); else, please clarify. Thanks.

aaron.ballman added inline comments.
clang/lib/Frontend/CompilerInvocation.cpp
4442

This function doesn't exist on Windows.

appcs added inline comments.Mar 28 2022, 3:08 PM
clang/lib/Frontend/CompilerInvocation.cpp
4442

Thank you; I am re-spinning with std::get_time().

appcs updated this revision to Diff 419021.Mar 29 2022, 5:31 PM
  • Re-spun with std::get_time().
  • Expanded regression test with multiple error scenarios.
appcs marked an inline comment as done.Mar 29 2022, 5:36 PM
appcs added a comment.EditedApr 1 2022, 2:28 PM

Bazel uses -Wno-builtin-macro-redefined -D__DATE__="redacted" -D__TIMESTAMP__="redacted" -D__TIME__="redacted".
For reproducibility purposes, this is sufficient. I have two questions:

  • Do we need the arbitrary time feature?

If you are saying that defining DATE, TIMESTAMP, TIME to an arbitrary time value, then that is the definition of the problem that we are trying to solve; else, please clarify. Thanks.

  • Should an arbitrary string like "redacted" be supported?

Via -ffixed-date-time the value would have to be formatted e.g. 1969-12-31T23:59:59 (RFC3339 without fractional seconds and timezone); else, please clarify. Thanks.

Please ignore. Thanks.

appcs added a comment.EditedApr 1 2022, 6:03 PM

(From D121040) Please let me know about the following and I will incorporate your feedback and submit subsequent patches for addressing these questions:

a. Disallow the simultaneous use of -Wdate-time/-Wpch-date-time and -ffixed-date-time=<timestamp>?
b. Disallow -ffixed-date-time=<timestamp>:

0. if PCH's are used
1. in PCH compilation

Also, (just as -Wdate-time warns on TIMESTAMP use), do we (in a separate patch), extend the scope of -Wpch-date-time to cover the use of TIMESTAMP is in a PCH?

Thank you.

Please ignore. Thanks.

appcs added a comment.Apr 1 2022, 6:10 PM

Bazel uses -Wno-builtin-macro-redefined -D__DATE__="redacted" -D__TIMESTAMP__="redacted" -D__TIME__="redacted".
For reproducibility purposes, this is sufficient. I have two questions:

  • Do we need the arbitrary time feature?
  • Should an arbitrary string like "redacted" be supported?

(After a fair amount of reading, and contemplation), I think I understand. Basically, Clang takes the (rightfully correct) stand that the very presence of the DATE, TIME and TIMESTAMP macros in the source makes the resulting binary irreproducible. Period.
Please could someone kindly confirm if I have understood correctly. Thank you.

MaskRay added a comment.EditedApr 1 2022, 6:48 PM

Bazel uses -Wno-builtin-macro-redefined -D__DATE__="redacted" -D__TIMESTAMP__="redacted" -D__TIME__="redacted".
For reproducibility purposes, this is sufficient. I have two questions:

  • Do we need the arbitrary time feature?
  • Should an arbitrary string like "redacted" be supported?

(After a fair amount of reading, and contemplation), I think I understand. Basically, Clang takes the (rightfully correct) stand that the very presence of the DATE, TIME and TIMESTAMP macros in the source makes the resulting binary irreproducible. Period.
Please could someone kindly confirm if I have understood correctly. Thank you.

Yeah, my question is whether we need the ability to set time to an arbitrary point and adjust the output of the three macros. Is it needed by a user?
For reproducibility purposes, the user can just set the macros to an arbitrary string, in Bazel's case, "redacted". The user doesn't care about the format with "redacted".

Created D135045 [Frontend] Recognize environment variable SOURCE_DATE_EPOCH. I think that's more likely what users want to use.