Fix temporary file name on Windows
authorYaxun (Sam) Liu <yaxun.liu@amd.com>
Fri, 13 Nov 2020 14:43:35 +0000 (09:43 -0500)
committerYaxun (Sam) Liu <yaxun.liu@amd.com>
Sun, 15 Nov 2020 13:11:05 +0000 (08:11 -0500)
Bound arch may contain ':', which is invalid in Windows file names.

This patch fixes that.

Differential Revision: https://reviews.llvm.org/D91421

clang/lib/Driver/Driver.cpp
clang/test/Driver/hip-windows-filename.hip [new file with mode: 0644]

index bcea011..5f4e7f2 100644 (file)
@@ -4692,9 +4692,16 @@ static bool HasPreprocessOutput(const Action &JA) {
 
 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)) {
diff --git a/clang/test/Driver/hip-windows-filename.hip b/clang/test/Driver/hip-windows-filename.hip
new file mode 100644 (file)
index 0000000..9244f16
--- /dev/null
@@ -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"