[llvm] [SPIR-V] Reject module-level inline assembly with a diagnostic (PR #199992)
Arseniy Obolenskiy via llvm-commits
llvm-commits at lists.llvm.org
Thu May 28 04:00:24 PDT 2026
https://github.com/aobolensk updated https://github.com/llvm/llvm-project/pull/199992
>From 971559479b370f8893a464109c9b2a2adb9579f0 Mon Sep 17 00:00:00 2001
From: Arseniy Obolenskiy <arseniy.obolenskiy at amd.com>
Date: Wed, 27 May 2026 16:12:44 +0200
Subject: [PATCH 1/3] [SPIR-V] Reject module-level inline assembly with a
diagnostic
Module level inline asm is unsupported, even with extension
---
llvm/lib/Target/SPIRV/SPIRVAsmPrinter.cpp | 4 ++++
.../module_asm_unsupported.ll | 15 +++++++++++++++
2 files changed, 19 insertions(+)
create mode 100644 llvm/test/CodeGen/SPIRV/extensions/SPV_INTEL_inline_assembly/module_asm_unsupported.ll
diff --git a/llvm/lib/Target/SPIRV/SPIRVAsmPrinter.cpp b/llvm/lib/Target/SPIRV/SPIRVAsmPrinter.cpp
index 3f10d52a61b0e..f558da5606d86 100644
--- a/llvm/lib/Target/SPIRV/SPIRVAsmPrinter.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVAsmPrinter.cpp
@@ -898,6 +898,10 @@ void SPIRVAsmPrinter::outputModuleSections() {
bool SPIRVAsmPrinter::doInitialization(Module &M) {
ModuleSectionsEmitted = false;
+ if (!M.getModuleInlineAsm().empty())
+ report_fatal_error(
+ "SPIR-V does not support module-level inline assembly", false);
+
// Register the NSDI handler before calling the base class so that
// AsmPrinter::doInitialization() calls Handler->beginModule(M) for it.
if (M.getNamedMetadata("llvm.dbg.cu")) {
diff --git a/llvm/test/CodeGen/SPIRV/extensions/SPV_INTEL_inline_assembly/module_asm_unsupported.ll b/llvm/test/CodeGen/SPIRV/extensions/SPV_INTEL_inline_assembly/module_asm_unsupported.ll
new file mode 100644
index 0000000000000..17641540350e4
--- /dev/null
+++ b/llvm/test/CodeGen/SPIRV/extensions/SPV_INTEL_inline_assembly/module_asm_unsupported.ll
@@ -0,0 +1,15 @@
+; RUN: not llc -O0 -mtriple=spirv32-unknown-unknown %s -o /dev/null 2>&1 | FileCheck %s
+; RUN: not llc -O0 -mtriple=spirv64-unknown-unknown %s -o /dev/null 2>&1 | FileCheck %s
+
+; SPIR-V has no binary analog for module-level inline assembly.
+; The backend must reject it with a clean diagnostic
+; rather than reach the unimplemented MC asm parser path.
+
+; CHECK: LLVM ERROR: SPIR-V does not support module-level inline assembly
+
+module asm "foo"
+
+define void @main() {
+entry:
+ ret void
+}
>From ea0dc92550838097106d41817d290d914721f56d Mon Sep 17 00:00:00 2001
From: Arseniy Obolenskiy <arseniy.obolenskiy at amd.com>
Date: Wed, 27 May 2026 16:51:28 +0200
Subject: [PATCH 2/3] fix fmt
---
llvm/lib/Target/SPIRV/SPIRVAsmPrinter.cpp | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/llvm/lib/Target/SPIRV/SPIRVAsmPrinter.cpp b/llvm/lib/Target/SPIRV/SPIRVAsmPrinter.cpp
index f558da5606d86..4c54cd724b530 100644
--- a/llvm/lib/Target/SPIRV/SPIRVAsmPrinter.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVAsmPrinter.cpp
@@ -899,8 +899,8 @@ void SPIRVAsmPrinter::outputModuleSections() {
bool SPIRVAsmPrinter::doInitialization(Module &M) {
ModuleSectionsEmitted = false;
if (!M.getModuleInlineAsm().empty())
- report_fatal_error(
- "SPIR-V does not support module-level inline assembly", false);
+ report_fatal_error("SPIR-V does not support module-level inline assembly",
+ false);
// Register the NSDI handler before calling the base class so that
// AsmPrinter::doInitialization() calls Handler->beginModule(M) for it.
>From 29b9fe69aae1c592913e56eda9a303cc876f8639 Mon Sep 17 00:00:00 2001
From: Arseniy Obolenskiy <arseniy.obolenskiy at amd.com>
Date: Thu, 28 May 2026 12:56:00 +0200
Subject: [PATCH 3/3] Address review comment
---
llvm/lib/Target/SPIRV/SPIRVAsmPrinter.cpp | 8 +++++---
.../SPV_INTEL_inline_assembly/module_asm_unsupported.ll | 2 +-
2 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/llvm/lib/Target/SPIRV/SPIRVAsmPrinter.cpp b/llvm/lib/Target/SPIRV/SPIRVAsmPrinter.cpp
index 4c54cd724b530..d670df537b798 100644
--- a/llvm/lib/Target/SPIRV/SPIRVAsmPrinter.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVAsmPrinter.cpp
@@ -898,9 +898,11 @@ void SPIRVAsmPrinter::outputModuleSections() {
bool SPIRVAsmPrinter::doInitialization(Module &M) {
ModuleSectionsEmitted = false;
- if (!M.getModuleInlineAsm().empty())
- report_fatal_error("SPIR-V does not support module-level inline assembly",
- false);
+ if (!M.getModuleInlineAsm().empty()) {
+ M.getContext().emitError(
+ "SPIR-V does not support module-level inline assembly");
+ M.setModuleInlineAsm("");
+ }
// Register the NSDI handler before calling the base class so that
// AsmPrinter::doInitialization() calls Handler->beginModule(M) for it.
diff --git a/llvm/test/CodeGen/SPIRV/extensions/SPV_INTEL_inline_assembly/module_asm_unsupported.ll b/llvm/test/CodeGen/SPIRV/extensions/SPV_INTEL_inline_assembly/module_asm_unsupported.ll
index 17641540350e4..53dd362962bdb 100644
--- a/llvm/test/CodeGen/SPIRV/extensions/SPV_INTEL_inline_assembly/module_asm_unsupported.ll
+++ b/llvm/test/CodeGen/SPIRV/extensions/SPV_INTEL_inline_assembly/module_asm_unsupported.ll
@@ -5,7 +5,7 @@
; The backend must reject it with a clean diagnostic
; rather than reach the unimplemented MC asm parser path.
-; CHECK: LLVM ERROR: SPIR-V does not support module-level inline assembly
+; CHECK: error: SPIR-V does not support module-level inline assembly
module asm "foo"
More information about the llvm-commits
mailing list