Skip to content

[stable][clang-cache] Introduce CLANG_CACHE_REDACT_TIME_MACROS environment variable #5340

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion clang/test/CAS/test-for-deterministic-outputs.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@

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

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

// CACHE-MISS: remark: compile job cache miss
// CACHE-MISS: remark: compile job cache miss

void getit(const char **p1, const char **p2, const char **p3) {
*p1 = __DATE__;
*p2 = __TIMESTAMP__;
*p3 = __TIME__;
}
7 changes: 7 additions & 0 deletions clang/tools/driver/CacheLauncherMode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,13 @@ clang::handleClangCacheInvocation(SmallVectorImpl<const char *> &Args,
}
Args.append({"-greproducible"});

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