Skip to content
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
13 changes: 10 additions & 3 deletions clang/lib/Driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6459,9 +6459,16 @@ const char *Driver::GetNamedOutputPath(Compilation &C, const JobAction &JA,
(JA.getOffloadingDeviceKind() == Action::OFK_OpenMP && TC &&
TC->getTriple().isAMDGPU()));
};
if (!AtTopLevel && JA.getType() == types::TY_LLVM_BC &&
(C.getArgs().hasArg(options::OPT_emit_llvm) ||
IsAMDRDCInCompilePhase(JA, C.getArgs())))

// The linker wrapper may not support the input and output files to be the
// same one, and without it -save-temps can fail.
bool IsLinkerWrapper =
JA.getType() == types::TY_Object && isa<LinkerWrapperJobAction>(JA);
bool IsEmitBitcode = JA.getType() == types::TY_LLVM_BC &&
(C.getArgs().hasArg(options::OPT_emit_llvm) ||
IsAMDRDCInCompilePhase(JA, C.getArgs()));

if (!AtTopLevel && (IsLinkerWrapper || IsEmitBitcode))
Suffixed += ".tmp";
Suffixed += '.';
Suffixed += Suffix;
Expand Down
9 changes: 9 additions & 0 deletions clang/test/Driver/hip-spirv-translator-new-driver.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// The --offload-new-driver was crashing when using -save-temps due to a failure in clang-linker-wrapper.
// The input and output files cannot be the same.

// RUN: %clang --offload-new-driver -### -save-temps -nogpuinc -nogpulib \
// RUN: --offload-arch=amdgcnspirv -x hip %s 2>&1 \
// RUN: | FileCheck %s

// CHECK-NOT: {{".*clang-linker-wrapper.*"}} {{.*}} "-o" "[[OUTPUT_FILE:.*.o]]" {{.*}}"[[OUTPUT_FILE]]"
// CHECK: {{".*clang-linker-wrapper.*"}} {{.*}} "-o" {{".*.tmp.o"}}