[PATCH] D91421: Fix temporary file name on Windows

Yaxun Liu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Nov 13 06:47:41 PST 2020


yaxunl created this revision.
yaxunl added a reviewer: tra.
yaxunl requested review of this revision.

Bound arch may contain ':', which is invalid in Windows file names.

This patch fixes that.


https://reviews.llvm.org/D91421

Files:
  clang/lib/Driver/Driver.cpp
  clang/test/Driver/hip-windows-filename.hip


Index: clang/test/Driver/hip-windows-filename.hip
===================================================================
--- /dev/null
+++ clang/test/Driver/hip-windows-filename.hip
@@ -0,0 +1,10 @@
+// REQUIRES: system-windows, clang-driver, amdgpu-registered-target
+
+// RUN: %clang -### -target x86_64-pc-windows-msvc \
+// RUN:   -x hip \
+// RUN:   --offload-arch=gfx908:xnack+ \
+// RUN:   -nogpuinc -nogpulib -save-temps \
+// RUN:   %s 2>&1 | FileCheck %s
+
+// CHECK: "-o" "hip-windows-filename-hip-amdgcn-amd-amdhsa-gfx908%xnack+.cui"
+// CHECK-NOT: "-o" "hip-windows-filename-hip-amdgcn-amd-amdhsa-gfx908:xnack+.cui"
\ No newline at end of file
Index: clang/lib/Driver/Driver.cpp
===================================================================
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -4635,9 +4635,16 @@
 
 const char *Driver::GetNamedOutputPath(Compilation &C, const JobAction &JA,
                                        const char *BaseInput,
-                                       StringRef BoundArch, bool AtTopLevel,
+                                       StringRef OrigBoundArch, bool AtTopLevel,
                                        bool MultipleArchs,
                                        StringRef OffloadingPrefix) const {
+  std::string BoundArch = OrigBoundArch.str();
+#if defined(_WIN32)
+  // BoundArch may contains ':', which is invalid in file names on Windows,
+  // therefore replace it with '%'.
+  std::replace(BoundArch.begin(), BoundArch.end(), ':', '%');
+#endif
+
   llvm::PrettyStackTraceString CrashInfo("Computing output path");
   // Output to a user requested destination?
   if (AtTopLevel && !isa<DsymutilJobAction>(JA) && !isa<VerifyJobAction>(JA)) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D91421.305123.patch
Type: text/x-patch
Size: 1733 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20201113/01740b05/attachment.bin>


More information about the cfe-commits mailing list