[llvm] [SPIR-V] Fix lowering of declarations with hidden visibility (PR #185029)

Dmitry Sidorov via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 9 15:49:24 PDT 2026


================
@@ -1197,11 +1197,23 @@ Type *reconstitutePeeledArrayType(Type *Ty) {
 
 std::optional<SPIRV::LinkageType::LinkageType>
 getSpirvLinkageTypeFor(const SPIRVSubtarget &ST, const GlobalValue &GV) {
-  if (GV.hasLocalLinkage() || GV.hasHiddenVisibility())
+  if (GV.hasLocalLinkage())
     return std::nullopt;
 
-  if (GV.isDeclarationForLinker())
+  if (GV.isDeclarationForLinker()) {
+    // Interface variables must not get Import linkage.
+    if (const auto *GVar = dyn_cast<GlobalVariable>(&GV)) {
+      auto SC = addressSpaceToStorageClass(GVar->getAddressSpace(), ST);
+      if (SC == SPIRV::StorageClass::Input ||
+          SC == SPIRV::StorageClass::Output ||
+          SC == SPIRV::StorageClass::PushConstant)
+        return std::nullopt;
+    }
     return SPIRV::LinkageType::Import;
+  }
+
+  if (GV.hasHiddenVisibility())
----------------
MrSidims wrote:

This is actually partially correct. Actually for externally_initialized GVs with hidden visibility should have Export linkage. But let me confirm this and fix in a follow-up patch.

https://github.com/llvm/llvm-project/pull/185029


More information about the llvm-commits mailing list