aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Frontend/CompilerInvocation.cpp
diff options
context:
space:
mode:
authorBen Langmuir <blangmuir@apple.com>2022-10-25 15:12:24 -0700
committerBen Langmuir <blangmuir@apple.com>2022-10-26 12:42:56 -0700
commit211f5af38af1810925343bb71d90ca8485e66300 (patch)
tree0dfe974e89f83dbd9350cc0f5b65ab21eec65bd7 /clang/lib/Frontend/CompilerInvocation.cpp
parent126db4674aa54a37af4349d39f22e506b93d15de (diff)
downloadllvm-211f5af38af1810925343bb71d90ca8485e66300.zip
llvm-211f5af38af1810925343bb71d90ca8485e66300.tar.gz
llvm-211f5af38af1810925343bb71d90ca8485e66300.tar.bz2
[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
Diffstat (limited to 'clang/lib/Frontend/CompilerInvocation.cpp')
-rw-r--r--clang/lib/Frontend/CompilerInvocation.cpp8
1 files changed, 6 insertions, 2 deletions
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<uint64_t>(std::numeric_limits<time_t>::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 {