@@ -1294,6 +1294,7 @@ Expected<StringRef> clang(ArrayRef<StringRef> InputFiles, const ArgList &Args,
12941294 StringRef Arch = Args.getLastArgValue (OPT_arch_EQ);
12951295 if (Arch.empty ())
12961296 Arch = " native" ;
1297+
12971298 // Create a new file to write the linked device image to. Assume that the
12981299 // input filename already has the device and architecture.
12991300 auto TempFileOrErr =
@@ -1302,13 +1303,19 @@ Expected<StringRef> clang(ArrayRef<StringRef> InputFiles, const ArgList &Args,
13021303 " img" );
13031304 if (!TempFileOrErr)
13041305 return TempFileOrErr.takeError ();
1305-
1306+ std::string TempFileName (*TempFileOrErr);
1307+ if (is_style_windows (llvm::sys::path::Style::native)) {
1308+ // Arch may contain ':' or '*', which is invalid in file names on
1309+ // Windows, therefore replace it with '@'.
1310+ std::replace (TempFileName.begin (), TempFileName.end (), ' :' , ' @' );
1311+ std::replace (TempFileName.begin (), TempFileName.end (), ' *' , ' @' );
1312+ }
13061313 StringRef OptLevel = Args.getLastArgValue (OPT_opt_level, " O2" );
13071314 SmallVector<StringRef, 16 > CmdArgs{
13081315 *ClangPath,
13091316 " --no-default-config" ,
13101317 " -o" ,
1311- *TempFileOrErr ,
1318+ TempFileName ,
13121319 Args.MakeArgString (" --target=" + Triple.getTriple ()),
13131320 Triple.isAMDGPU () ? Args.MakeArgString (" -mcpu=" + Arch)
13141321 : Args.MakeArgString (" -march=" + Arch),
@@ -1395,7 +1402,7 @@ Expected<StringRef> clang(ArrayRef<StringRef> InputFiles, const ArgList &Args,
13951402 if (Error Err = executeCommands (*ClangPath, CmdArgs))
13961403 return std::move (Err);
13971404
1398- return *TempFileOrErr ;
1405+ return TempFileName ;
13991406}
14001407} // namespace generic
14011408
@@ -1526,6 +1533,12 @@ std::unique_ptr<lto::LTO> createLTO(
15261533 std::string TempName = (sys::path::filename (ExecutableName) + " ." +
15271534 Triple.getTriple () + " ." + Arch)
15281535 .str ();
1536+ if (is_style_windows (llvm::sys::path::Style::native)) {
1537+ // Arch may contain ':' or '*', which is invalid in file names on
1538+ // Windows, therefore replace it with '@'.
1539+ std::replace (TempName.begin (), TempName.end (), ' :' , ' @' );
1540+ std::replace (TempName.begin (), TempName.end (), ' *' , ' @' );
1541+ }
15291542 Conf.PostInternalizeModuleHook = [=](size_t Task, const Module &M) {
15301543 std::string File =
15311544 !Task ? TempName + " .postlink.bc"
0 commit comments