Skip to content

Commit 8ca6c91

Browse files
authored
[Driver] -save-temps issue with files in CWD (#7955)
When using -save-temps against fails in the $CWD, the driver was avoiding creating the intermediate files in the $CWD and creating them in /tmp. A previous modification to improve our behaviors with potential clashing intermediate files when working with llvm-foreach compilations inadvertently modified the check for the output name matching the base input name. Put this check back in.
1 parent c8a1e67 commit 8ca6c91

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

clang/lib/Driver/Driver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9015,7 +9015,7 @@ const char *Driver::GetNamedOutputPath(Compilation &C, const JobAction &JA,
90159015
if (isSaveTempsEnabled()) {
90169016
// If we're saving temps and the temp file conflicts with any
90179017
// input/resulting file, then avoid overwriting.
9018-
if (!AtTopLevel) {
9018+
if (!AtTopLevel && NamedOutput == BaseName) {
90199019
bool SameFile = false;
90209020
SmallString<256> Result;
90219021
llvm::sys::fs::current_path(Result);

clang/test/Driver/save-temps.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,11 @@
9393
// CHECK-SAVE-TEMPS-CMSE: -cc1as
9494
// CHECK-SAVE-TEMPS-CMSE: +8msecext
9595
// CHECK-SAVE-TEMPS-CMSE-NOT: '+cmse' is not a recognized feature for this target (ignoring feature)
96+
97+
// Usage of -save-temps with a file in $CWD should create the intermediate
98+
// files _not_ in /tmp.
99+
//
100+
// RUN: touch dummy.c
101+
// RUN: %clang -save-temps dummy.c -### 2>&1 \
102+
// RUN: | FileCheck %s -check-prefix=CHECK-CWD-FILE
103+
// CHECK-CWD-FILE: clang{{.*}} "-o" "dummy.ii"

0 commit comments

Comments
 (0)