[llvm-branch-commits] [clang] aa2bbfa - [CUDA] Fix output from ptxas being removes as a temporary file

Tom Stellard via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Tue Feb 7 17:13:38 PST 2023


Author: Joseph Huber
Date: 2023-02-07T17:12:10-08:00
New Revision: aa2bbfaee2d5b352f7ab1a990c1e40535c6fb51b

URL: https://github.com/llvm/llvm-project/commit/aa2bbfaee2d5b352f7ab1a990c1e40535c6fb51b
DIFF: https://github.com/llvm/llvm-project/commit/aa2bbfaee2d5b352f7ab1a990c1e40535c6fb51b.diff

LOG: [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.

Added: 
    

Modified: 
    clang/lib/Driver/ToolChains/Cuda.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Driver/ToolChains/Cuda.cpp b/clang/lib/Driver/ToolChains/Cuda.cpp
index 484c8c0702643..9a231c06a0749 100644
--- a/clang/lib/Driver/ToolChains/Cuda.cpp
+++ b/clang/lib/Driver/ToolChains/Cuda.cpp
@@ -443,7 +443,7 @@ void NVPTX::Assembler::ConstructJob(Compilation &C, const JobAction &JA,
   CmdArgs.push_back("--gpu-name");
   CmdArgs.push_back(Args.MakeArgString(CudaArchToString(gpu_arch)));
   CmdArgs.push_back("--output-file");
-  const char *OutputFileName = Args.MakeArgString(TC.getInputFilename(Output));
+  std::string OutputFileName = TC.getInputFilename(Output);
 
   // If we are invoking `nvlink` internally we need to output a `.cubin` file.
   // 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,
           C.getTempFiles().end()) {
     SmallString<256> Filename(Output.getFilename());
     llvm::sys::path::replace_extension(Filename, "cubin");
-    OutputFileName = Args.MakeArgString(Filename);
+    OutputFileName = Filename.str();
   }
   if (Output.isFilename() && OutputFileName != Output.getFilename())
-    C.addTempFile(OutputFileName);
+    C.addTempFile(Args.MakeArgString(OutputFileName));
 
-  CmdArgs.push_back(OutputFileName);
+  CmdArgs.push_back(Args.MakeArgString(OutputFileName));
   for (const auto &II : Inputs)
     CmdArgs.push_back(Args.MakeArgString(II.getFilename()));
 


        


More information about the llvm-branch-commits mailing list