https://github.com/mgcarrasco created 
https://github.com/llvm/llvm-project/pull/231471

An amdgcnspirv device-only compile without -o wrote a SPIR-V binary with a .out 
suffix. Use .spv for that case.

Fixes LCOMPILER-356.

>From 9f6b7f13fd066e403968125b5b9c7db06c7d4154 Mon Sep 17 00:00:00 2001
From: Manuel Carrasco <[email protected]>
Date: Tue, 13 Oct 2026 07:10:51 -0500
Subject: [PATCH] [Clang][Driver] Name unbundled non-RDC HIP SPIR-V images .spv

An amdgcnspirv device-only compile without -o wrote a SPIR-V binary
with a .out suffix. Use .spv for that case.
---
 clang/lib/Driver/Driver.cpp                   | 10 +++++--
 .../test/Driver/hip-amdgcnspirv-output-name.c | 30 +++++++++++++++++++
 2 files changed, 38 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/Driver/hip-amdgcnspirv-output-name.c

diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index b2dbc32f1b89fd..bcc45bbf17cb82 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -5756,8 +5756,14 @@ const char *Driver::GetNamedOutputPath(Compilation &C, 
const JobAction &JA,
         Output += "-";
         Output.append(BoundArchStr);
       }
-      if (UseOutExtension)
-        Output += ".out";
+      if (UseOutExtension) {
+        const ToolChain *OffloadTC = JA.getOffloadingToolChain();
+        const bool IsHIPSPIRV = IsHIPNoRDC &&
+                                !isa<OffloadPackagerJobAction>(JA) &&
+                                OffloadTC && OffloadTC->getTriple().isSPIRV();
+        // Use .spv when the requested output is SPIR-V.
+        Output += IsHIPSPIRV ? ".spv" : ".out";
+      }
       NamedOutput = C.getArgs().MakeArgString(Output.c_str());
     }
   } else if (JA.getType() == types::TY_PCH && IsCLMode()) {
diff --git a/clang/test/Driver/hip-amdgcnspirv-output-name.c 
b/clang/test/Driver/hip-amdgcnspirv-output-name.c
new file mode 100644
index 00000000000000..706d14ae0a55b7
--- /dev/null
+++ b/clang/test/Driver/hip-amdgcnspirv-output-name.c
@@ -0,0 +1,30 @@
+// RUN: %clang -### --target=x86_64-unknown-linux-gnu \
+// RUN:   --offload-arch=amdgcnspirv --offload-device-only 
--no-gpu-bundle-output \
+// RUN:   -nogpuinc -nogpulib -x hip %s 2>&1 \
+// RUN: | FileCheck -check-prefix=SPIRV %s
+
+// RUN: %clang -### --target=x86_64-unknown-linux-gnu \
+// RUN:   --offload-arch=amdgcnspirv --offload-device-only 
--no-gpu-bundle-output \
+// RUN:   -nogpuinc -nogpulib -c -x hip %s 2>&1 \
+// RUN: | FileCheck -check-prefix=SPIRV %s
+
+// SPIRV: "-triple=spirv64-amd-amdhsa" "-emit-obj"{{.*}} "-o" 
"hip-amdgcnspirv-output-name-hip-spirv64-amd-amdhsa-amdgcnspirv.spv"
+// SPIRV-NOT: "-o" 
"hip-amdgcnspirv-output-name-hip-spirv64-amd-amdhsa-amdgcnspirv.out"
+
+// -c -emit-llvm still links that same SPIR-V image.
+// RUN: %clang -### --target=x86_64-unknown-linux-gnu \
+// RUN:   --offload-arch=amdgcnspirv --offload-device-only 
--no-gpu-bundle-output \
+// RUN:   -nogpuinc -nogpulib -c -emit-llvm -x hip %s 2>&1 \
+// RUN: | FileCheck -check-prefix=SPIRV-EMIT-LLVM %s
+
+// SPIRV-EMIT-LLVM: "-triple=spirv64-amd-amdhsa" "-emit-obj"{{.*}} "-o" 
"hip-amdgcnspirv-output-name-hip-spirv64-amd-amdhsa-amdgcnspirv.spv"
+// SPIRV-EMIT-LLVM-NOT: "-o" 
"hip-amdgcnspirv-output-name-hip-spirv64-amd-amdhsa-amdgcnspirv.out"
+
+// The translator path uses the same filename.
+// RUN: %clang -### --target=x86_64-unknown-linux-gnu \
+// RUN:   --offload-arch=amdgcnspirv --offload-device-only 
--no-gpu-bundle-output \
+// RUN:   -nogpuinc -nogpulib -no-use-spirv-backend -x hip %s 2>&1 \
+// RUN: | FileCheck -check-prefix=TRANSLATOR %s
+
+// TRANSLATOR: "llvm-spirv"{{.*}} "-o" 
"hip-amdgcnspirv-output-name-hip-spirv64-amd-amdhsa-amdgcnspirv.spv"
+// TRANSLATOR-NOT: "-o" 
"hip-amdgcnspirv-output-name-hip-spirv64-amd-amdhsa-amdgcnspirv.out"

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to