Skip to content

Commit d3fcdac

Browse files
authored
Merge pull request #5340 from akyrtzi/pr/stable/redact-date-time-for-testing
[stable][clang-cache] Introduce `CLANG_CACHE_REDACT_TIME_MACROS` environment variable
2 parents c205842 + 26c646f commit d3fcdac

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

clang/test/CAS/test-for-deterministic-outputs.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,15 @@
22

33
// This compiles twice with replay disabled, ensuring that we get the same outputs for the same key.
44

5-
// RUN: env LLVM_CACHE_CAS_PATH=%t/cas CLANG_CACHE_TEST_DETERMINISTIC_OUTPUTS=1 %clang-cache \
5+
// RUN: env LLVM_CACHE_CAS_PATH=%t/cas CLANG_CACHE_TEST_DETERMINISTIC_OUTPUTS=1 CLANG_CACHE_REDACT_TIME_MACROS=1 %clang-cache \
66
// RUN: %clang -target x86_64-apple-macos11 -c %s -o %t/t.o -Rcompile-job-cache 2> %t/out.txt
77
// RUN: FileCheck %s --check-prefix=CACHE-MISS --input-file=%t/out.txt
88

99
// CACHE-MISS: remark: compile job cache miss
1010
// CACHE-MISS: remark: compile job cache miss
11+
12+
void getit(const char **p1, const char **p2, const char **p3) {
13+
*p1 = __DATE__;
14+
*p2 = __TIMESTAMP__;
15+
*p3 = __TIME__;
16+
}

clang/tools/driver/CacheLauncherMode.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,13 @@ clang::handleClangCacheInvocation(SmallVectorImpl<const char *> &Args,
171171
}
172172
Args.append({"-greproducible"});
173173

174+
if (llvm::sys::Process::GetEnv("CLANG_CACHE_REDACT_TIME_MACROS")) {
175+
// Remove use of these macros to get reproducible outputs. This can
176+
// accompany CLANG_CACHE_TEST_DETERMINISTIC_OUTPUTS to avoid fatal errors
177+
// when the source uses these macros.
178+
Args.append({"-Wno-builtin-macro-redefined", "-D__DATE__=\"redacted\"",
179+
"-D__TIMESTAMP__=\"redacted\"", "-D__TIME__=\"redacted\""});
180+
}
174181
if (llvm::sys::Process::GetEnv("CLANG_CACHE_TEST_DETERMINISTIC_OUTPUTS")) {
175182
// Run the compilation twice, without replaying, to check that we get the
176183
// same compilation artifacts for the same key. If they are not the same

0 commit comments

Comments
 (0)