diff --git a/clang/lib/Driver/ToolChains/Cuda.cpp b/clang/lib/Driver/ToolChains/Cuda.cpp --- a/clang/lib/Driver/ToolChains/Cuda.cpp +++ b/clang/lib/Driver/ToolChains/Cuda.cpp @@ -447,7 +447,10 @@ CmdArgs.push_back("--gpu-name"); CmdArgs.push_back(Args.MakeArgString(CudaArchToString(gpu_arch))); CmdArgs.push_back("--output-file"); - CmdArgs.push_back(Args.MakeArgString(TC.getInputFilename(Output))); + const char *OutputFileName = Args.MakeArgString(TC.getInputFilename(Output)); + if (std::string(OutputFileName) != std::string(Output.getFilename())) + C.addTempFile(OutputFileName); + CmdArgs.push_back(OutputFileName); for (const auto& II : Inputs) CmdArgs.push_back(Args.MakeArgString(II.getFilename())); @@ -606,8 +609,8 @@ if (!II.isFilename()) continue; - const char *CubinF = C.addTempFile( - C.getArgs().MakeArgString(getToolChain().getInputFilename(II))); + const char *CubinF = + C.getArgs().MakeArgString(getToolChain().getInputFilename(II)); CmdArgs.push_back(CubinF); }