From 211f5af38af1810925343bb71d90ca8485e66300 Mon Sep 17 00:00:00 2001 From: Ben Langmuir Date: Tue, 25 Oct 2022 15:12:24 -0700 Subject: [clang] Move getenv call for SOURCE_DATE_EPOCH out of frontend NFC 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. Differential Revision: https://reviews.llvm.org/D136717 --- clang/lib/Frontend/CompilerInvocation.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'clang/lib/Frontend/CompilerInvocation.cpp') diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index bcd5359..9cd6d86 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -4227,6 +4227,9 @@ static void GeneratePreprocessorArgs(PreprocessorOptions &Opts, for (const auto &RF : Opts.RemappedFiles) GenerateArg(Args, OPT_remap_file, RF.first + ";" + RF.second, SA); + if (Opts.SourceDateEpoch) + GenerateArg(Args, OPT_source_date_epoch, Twine(*Opts.SourceDateEpoch), SA); + // Don't handle LexEditorPlaceholders. It is implied by the action that is // generated elsewhere. } @@ -4309,14 +4312,15 @@ static bool ParsePreprocessorArgs(PreprocessorOptions &Opts, ArgList &Args, Opts.addRemappedFile(Split.first, Split.second); } - if (const char *Epoch = std::getenv("SOURCE_DATE_EPOCH")) { + if (const Arg *A = Args.getLastArg(OPT_source_date_epoch)) { + StringRef Epoch = A->getValue(); // SOURCE_DATE_EPOCH, if specified, must be a non-negative decimal integer. // On time64 systems, pick 253402300799 (the UNIX timestamp of // 9999-12-31T23:59:59Z) as the upper bound. const uint64_t MaxTimestamp = std::min(std::numeric_limits::max(), 253402300799); uint64_t V; - if (StringRef(Epoch).getAsInteger(10, V) || V > MaxTimestamp) { + if (Epoch.getAsInteger(10, V) || V > MaxTimestamp) { Diags.Report(diag::err_fe_invalid_source_date_epoch) << Epoch << MaxTimestamp; } else { -- cgit v1.1