[llvm] [SPIRV] Fix legalization of zero-sized intrinsic globals (PR #192730)

Dmitry Sidorov via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 21 04:09:47 PDT 2026


================
@@ -298,12 +298,23 @@ bool SPIRVLegalizeZeroSizeArraysImpl::runOnModule(Module &M) {
 
     Type *NewTy = legalizeType(GV.getValueType());
     Constant *LegalizedInitializer =
-        GV.hasInitializer() ? legalizeConstant(GV.getInitializer()) : nullptr;
+        GV.hasInitializer() && !GV.hasAppendingLinkage()
+            ? legalizeConstant(GV.getInitializer())
+            : nullptr;
+
+    // The new global will have the same linkage type as the original,
+    // except in the case that it is an llvm intrinsic global such as
+    // llvm.global_ctors with appending linkage, in which case we need to change
+    // the linkage as appending linkage is only allowed for arrays.
+    GlobalValue::LinkageTypes NewLT =
+        GV.hasAppendingLinkage()
+            ? GlobalValue::LinkageTypes::ExternalWeakLinkage
----------------
MrSidims wrote:

Note, it won't survive SPIR-V round trip.

Good news, I'll publish an extension around today adding weak linkage. Would it be useful for you?

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


More information about the llvm-commits mailing list