fix(match): REnum match 变体字段绑定前确保跨模块结构体完整定义

_bind_variant_fields 对 renum_ty 做带字段下标的 GEP,LLVM 要求被指结构体 sized;而模块内对跨模块 REnum(如 llvmlite.__types.LLVMType)只有签名扫描产生的 type opaque,作 GEP base element 时 llc 报 base element of getelementptr must be sized(LLvmLiteTest 根因)。其它取字段路径在 GEP 前都会调 ensure_struct_def_in_module,唯独 REnum match 绑定漏了。补上该调用(同名原地替换 opaque,非追加;本地非跨模块类型自动跳过)。
This commit is contained in:
TermiNexus committed 2026-10-03 11:21:41 +08:00
1 parent 105456e56e
commit 18f4c2326f
1 file changed
+11
+11
View File
@@ -665,6 +665,17 @@ novirtual class MatchGenMixin:
renum_entry = se_v
renum_ty = se_v.Ty
# 6b. 跨模块 REnum:变体字段绑定(step 7/_bind_variant_fields)会对
# renum_ty 做带字段下标的 GEP,LLVM 要求被指结构体 sized(有完整定义)。
# 签名扫描(ensure_opaque_for_type)只为 Ptr(Struct) 发 `type opaque`,
# 不透明类型作 GEP base element 时 llc 报
# "base element of getelementptr must be sized"(__values.vp 匹配
# __types.LLVMType 的根因)。此处用结构体表 entry.Ty 的完整定义**同名替换**
# opaque(module_add_named_type 原地替换,非追加,故不会 invalid redefinition);
# 本地非跨模块类型(名不含 '.')会自动跳过。
if renum_ty is not None:
self.Gen.StructGen.ensure_struct_def_in_module(pool, trans.Module, renum_ty)
# 7. 第二遍:翻译每个 case body
i = 0
while i < collected: