Skip to content

Commit aa2bbfa

Browse files
jhuber6tstellar
authored andcommitted
[CUDA] Fix output from ptxas being removes as a temporary file
Summary: The logic here is to add the `.cubin` temporary file if we had to create a new filename to handle it. Unfortuantely the logic was wrong because we compare `const char *` values here. This logic seems to have been wrong for some time, but was never noticed since we never used the relocatable output.
1 parent c4392bc commit aa2bbfa

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

clang/lib/Driver/ToolChains/Cuda.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ void NVPTX::Assembler::ConstructJob(Compilation &C, const JobAction &JA,
443443
CmdArgs.push_back("--gpu-name");
444444
CmdArgs.push_back(Args.MakeArgString(CudaArchToString(gpu_arch)));
445445
CmdArgs.push_back("--output-file");
446-
const char *OutputFileName = Args.MakeArgString(TC.getInputFilename(Output));
446+
std::string OutputFileName = TC.getInputFilename(Output);
447447

448448
// If we are invoking `nvlink` internally we need to output a `.cubin` file.
449449
// Checking if the output is a temporary is the cleanest way to determine
@@ -455,12 +455,12 @@ void NVPTX::Assembler::ConstructJob(Compilation &C, const JobAction &JA,
455455
C.getTempFiles().end()) {
456456
SmallString<256> Filename(Output.getFilename());
457457
llvm::sys::path::replace_extension(Filename, "cubin");
458-
OutputFileName = Args.MakeArgString(Filename);
458+
OutputFileName = Filename.str();
459459
}
460460
if (Output.isFilename() && OutputFileName != Output.getFilename())
461-
C.addTempFile(OutputFileName);
461+
C.addTempFile(Args.MakeArgString(OutputFileName));
462462

463-
CmdArgs.push_back(OutputFileName);
463+
CmdArgs.push_back(Args.MakeArgString(OutputFileName));
464464
for (const auto &II : Inputs)
465465
CmdArgs.push_back(Args.MakeArgString(II.getFilename()));
466466

0 commit comments

Comments
 (0)