Skip to content

Commit 14ee2b0

Browse files
committed
[clang][Driver] Fix crash in --offload-new-driver and -save-temps.
1 parent 957598f commit 14ee2b0

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

clang/lib/Driver/Driver.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6459,9 +6459,16 @@ const char *Driver::GetNamedOutputPath(Compilation &C, const JobAction &JA,
64596459
(JA.getOffloadingDeviceKind() == Action::OFK_OpenMP && TC &&
64606460
TC->getTriple().isAMDGPU()));
64616461
};
6462-
if (!AtTopLevel && JA.getType() == types::TY_LLVM_BC &&
6463-
(C.getArgs().hasArg(options::OPT_emit_llvm) ||
6464-
IsAMDRDCInCompilePhase(JA, C.getArgs())))
6462+
6463+
// The linker wrapper may not support the input and output files to be the
6464+
// same one, and without it -save-temps can fail.
6465+
bool IsLinkerWrapper =
6466+
JA.getType() == types::TY_Object && isa<LinkerWrapperJobAction>(JA);
6467+
bool IsEmitBitcode = JA.getType() == types::TY_LLVM_BC &&
6468+
(C.getArgs().hasArg(options::OPT_emit_llvm) ||
6469+
IsAMDRDCInCompilePhase(JA, C.getArgs()));
6470+
6471+
if (!AtTopLevel && (IsLinkerWrapper || IsEmitBitcode))
64656472
Suffixed += ".tmp";
64666473
Suffixed += '.';
64676474
Suffixed += Suffix;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// The --offload-new-driver was crashing when using -save-temps due to a failure in clang-linker-wrapper.
2+
// The input and output files cannot be the same.
3+
4+
// RUN: %clang --offload-new-driver -### -save-temps -nogpuinc -nogpulib \
5+
// RUN: --offload-arch=amdgcnspirv -x hip %s 2>&1 \
6+
// RUN: | FileCheck %s
7+
8+
// CHECK-NOT: {{".*clang-linker-wrapper.*"}} {{.*}} "-o" "[[OUTPUT_FILE:.*.o]]" {{.*}}"[[OUTPUT_FILE]]"
9+
// CHECK: {{".*clang-linker-wrapper.*"}} {{.*}} "-o" {{".*.tmp.o"}}

0 commit comments

Comments
 (0)