@@ -1294,6 +1294,7 @@ Expected<StringRef> clang(ArrayRef<StringRef> InputFiles, const ArgList &Args,
1294
1294
StringRef Arch = Args.getLastArgValue (OPT_arch_EQ);
1295
1295
if (Arch.empty ())
1296
1296
Arch = " native" ;
1297
+
1297
1298
// Create a new file to write the linked device image to. Assume that the
1298
1299
// input filename already has the device and architecture.
1299
1300
auto TempFileOrErr =
@@ -1302,13 +1303,19 @@ Expected<StringRef> clang(ArrayRef<StringRef> InputFiles, const ArgList &Args,
1302
1303
" img" );
1303
1304
if (!TempFileOrErr)
1304
1305
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
+ }
1306
1313
StringRef OptLevel = Args.getLastArgValue (OPT_opt_level, " O2" );
1307
1314
SmallVector<StringRef, 16 > CmdArgs{
1308
1315
*ClangPath,
1309
1316
" --no-default-config" ,
1310
1317
" -o" ,
1311
- *TempFileOrErr ,
1318
+ TempFileName ,
1312
1319
Args.MakeArgString (" --target=" + Triple.getTriple ()),
1313
1320
Triple.isAMDGPU () ? Args.MakeArgString (" -mcpu=" + Arch)
1314
1321
: Args.MakeArgString (" -march=" + Arch),
@@ -1395,7 +1402,7 @@ Expected<StringRef> clang(ArrayRef<StringRef> InputFiles, const ArgList &Args,
1395
1402
if (Error Err = executeCommands (*ClangPath, CmdArgs))
1396
1403
return std::move (Err);
1397
1404
1398
- return *TempFileOrErr ;
1405
+ return TempFileName ;
1399
1406
}
1400
1407
} // namespace generic
1401
1408
@@ -1526,6 +1533,12 @@ std::unique_ptr<lto::LTO> createLTO(
1526
1533
std::string TempName = (sys::path::filename (ExecutableName) + " ." +
1527
1534
Triple.getTriple () + " ." + Arch)
1528
1535
.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
+ }
1529
1542
Conf.PostInternalizeModuleHook = [=](size_t Task, const Module &M) {
1530
1543
std::string File =
1531
1544
!Task ? TempName + " .postlink.bc"
0 commit comments