Skip to content

Commit 692d150

Browse files
committed
[clang][cas] Only handle CLANG_CACHE_TEST_DETERMINISTIC_OUTPUTS with caching
When caching is disabled, we don't want to run the compile twice. First, because it is wasteful when we won't detect any issues. Second, because it works around errors with -E writing twice to stdout in scripts. Technically, we could have caching enabled with -E or -o - and see the same issue, but it's non-trivial to fix that without introducing maintenance issues in cc1_main until we upstream this code. rdar://109163869 (cherry picked from commit 99a1a13)
1 parent 0ff521f commit 692d150

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@
4545
// NOERROR-NOT: error:
4646
// ERROR: error: encountered non-reproducible token, caching will be skipped
4747

48+
// Verify we don't double output without caching enabled.
49+
// RUN: env CLANG_CACHE_TEST_DETERMINISTIC_OUTPUTS=1 %clang -E %s | FileCheck %s -check-prefix=NO_CACHE
50+
// NO_CACHE: getit
51+
// NO_CACHE-NOT: getit
52+
4853
void getit(const char **p1, const char **p2, const char **p3) {
4954
*p1 = __DATE__;
5055
*p2 = __TIMESTAMP__;

clang/tools/driver/driver.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,8 +367,13 @@ static int ExecuteCC1Tool(SmallVectorImpl<const char *> &ArgV) {
367367
StringRef Tool = ArgV[1];
368368
void *GetExecutablePathVP = (void *)(intptr_t)GetExecutablePath;
369369
if (Tool == "-cc1") {
370-
if (std::getenv("CLANG_CACHE_TEST_DETERMINISTIC_OUTPUTS")) {
371-
// Perform the compile twice in order to catch differences in the output.
370+
if (std::getenv("CLANG_CACHE_TEST_DETERMINISTIC_OUTPUTS") &&
371+
find(ArgV, StringRef("-fcache-compile-job")) != ArgV.end()) {
372+
// With caching enabled, perform the compile twice in order to catch
373+
// differences in the output.
374+
// FIXME: while it is unlikely caching will be enabled when the output
375+
// is to stdout (e.g. `-E`, or `-S -o -`), we should avoid writing
376+
// output twice.
372377
int RC = cc1_main(ArrayRef(ArgV).slice(1), ArgV[0], GetExecutablePathVP);
373378
if (RC != 0)
374379
return RC;

0 commit comments

Comments
 (0)