[llvm] 5033573 - [SPIR-V] Drop initializer for Import linkage type globals (#190942)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 8 14:44:36 PDT 2026
Author: Arseniy Obolenskiy
Date: 2026-04-08T23:44:31+02:00
New Revision: 503357350ce915a53a8147ac584d8b9ae4814be7
URL: https://github.com/llvm/llvm-project/commit/503357350ce915a53a8147ac584d8b9ae4814be7
DIFF: https://github.com/llvm/llvm-project/commit/503357350ce915a53a8147ac584d8b9ae4814be7.diff
LOG: [SPIR-V] Drop initializer for Import linkage type globals (#190942)
Per SPIR-V spec, variable with Import linkage must not have initializer
Fix corresponding spirv-val error:
```
error: A module-scope OpVariable with initialization value cannot be marked with the Import Linkage Type.
```
related to https://github.com/llvm/llvm-project/issues/190736
Added:
Modified:
llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp
llvm/test/CodeGen/SPIRV/linkage/linkage-types.ll
Removed:
################################################################################
diff --git a/llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp b/llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp
index 9da8397efc22f..0144757a0cf24 100644
--- a/llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp
@@ -6156,6 +6156,9 @@ bool SPIRVInstructionSelector::selectGlobalValue(
const std::optional<SPIRV::LinkageType::LinkageType> LnkType =
getSpirvLinkageTypeFor(STI, *GV);
+ if (LnkType && *LnkType == SPIRV::LinkageType::Import)
+ Init = nullptr;
+
const unsigned AddrSpace = GV->getAddressSpace();
SPIRV::StorageClass::StorageClass StorageClass =
addressSpaceToStorageClass(AddrSpace, STI);
diff --git a/llvm/test/CodeGen/SPIRV/linkage/linkage-types.ll b/llvm/test/CodeGen/SPIRV/linkage/linkage-types.ll
index b1c48db1f209f..dbe86ecac9c4b 100644
--- a/llvm/test/CodeGen/SPIRV/linkage/linkage-types.ll
+++ b/llvm/test/CodeGen/SPIRV/linkage/linkage-types.ll
@@ -1,4 +1,5 @@
; RUN: llc -O0 -mtriple=spirv32-unknown-unknown %s -o - | FileCheck %s --check-prefix=SPIRV
+; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv32-unknown-unknown %s -o - -filetype=obj | spirv-val %}
; SPIRV: OpCapability Linkage
; SPIRV: OpEntryPoint Kernel %[[#kern:]] "kern"
More information about the llvm-commits
mailing list