fix(codegen): 字段表↔槽位一致性护栏豁免联合体

union 的字段表有 N 条(每成员一条)但 LLVM 布局只有 1 个槽位(成员全偏移 0、按最大成员定宽),二者本不相等;字段访问走 bitcast 到字段类型后的 GEP,不依赖槽位下标。误报实证:EdgeCaseTest 的 class Data(t.CUnion)(i_val/f_val 两成员 → 1 槽)被护栏拦下。
This commit is contained in:
TermiNexus committed 2026-09-27 17:26:04 +08:00
1 parent 0279965074
commit e65f04f16b
1 file changed
+6
+6
View File
@@ -986,6 +986,12 @@ novirtual class StructGenMixin:
return 0
if entry.FieldCount <= 0:
return 0
# 联合体豁免:union 的字段表有 N 条(每个成员一条),但 LLVM 布局只有 **1 个
# 槽位**(成员全部偏移 0、按最大成员定宽),二者本就不相等;字段访问走的是
# bitcast 到字段类型后的 GEP(见 ExprGenAttr 的 union 分支),不依赖槽位下标,
# 故本护栏不适用(误报实证:EdgeCaseTest 的 `class Data(t.CUnion)`,2 成员 → 1 槽)。
if entry.IsUnion != 0 or self.is_union_by_type(struct_ty) != 0:
return 0
fcount: int = llvmlite.get_struct_fcount(struct_ty)
if fcount <= 0:
return 0