This is an archive of the discontinued LLVM Phabricator instance.

[clang] Move getenv call for SOURCE_DATE_EPOCH out of frontend NFC
ClosedPublic

Authored by benlangmuir on Oct 25 2022, 3:44 PM.

Details

Summary

Move the check for SOURCE_DATE_EPOCH to the driver and use a cc1 option to pass it to the frontend. This avoids hidden state in the cc1 invocation and makes this env variable behave more like other env variables that clang handles in the driver.

Diff Detail

Event Timeline

benlangmuir created this revision.Oct 25 2022, 3:44 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 25 2022, 3:44 PM
Herald added a subscriber: StephenFan. · View Herald Transcript
benlangmuir requested review of this revision.Oct 25 2022, 3:44 PM
MaskRay accepted this revision.Oct 25 2022, 3:50 PM
MaskRay added inline comments.
clang/lib/Frontend/CompilerInvocation.cpp
4324

Is it worth making err_fe_invalid_source_date_epoch a driver diagnostic? I think driver validation is more common.

clang/test/Driver/SOURCE_DATE_EPOCH.c
3

In case someone put the build directory under a directory with the string -source-date-epoch, even if it is highly unlikely.

This revision is now accepted and ready to land.Oct 25 2022, 3:50 PM
benlangmuir added inline comments.Oct 25 2022, 4:09 PM
clang/lib/Frontend/CompilerInvocation.cpp
4324

I wasn't sure if we could just move the validation to the driver or if we would end up duplicating it -- how bad is it to have a value that's too large? If it could cause UB or something I wouldn't want to remove the check from the frontend.

This revision was landed with ongoing or failed builds.Oct 26 2022, 12:43 PM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptOct 26 2022, 12:43 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
benlangmuir added inline comments.Oct 26 2022, 12:43 PM
clang/lib/Frontend/CompilerInvocation.cpp
4324

I kept the validation in the frontend for now but happy to iterate on this if you'd like.

clang/test/Driver/SOURCE_DATE_EPOCH.c
3

Fair point, done!

tstellar added inline comments.
clang/test/Driver/SOURCE_DATE_EPOCH.c
2

Hi @benlangmuir, this test fails in our build environment, because we have the SOURCE_DATE_EPOCH env variable set globally. Is there any way to update the test to handle this scenario?

benlangmuir added inline comments.Jan 24 2023, 3:38 PM
clang/test/Driver/SOURCE_DATE_EPOCH.c
2

I'm not aware of a portable way to unset environment variables (env -u doesn't work on some of our platforms) and this first check is low-value anyway, so I'm fine with just dropping it and only having the ones below that explicitly set a value. https://reviews.llvm.org/D142511