diff --git a/App/lib/core/Gen/StructGenMixin.vp b/App/lib/core/Gen/StructGenMixin.vp index a3d62f6..47429ad 100644 --- a/App/lib/core/Gen/StructGenMixin.vp +++ b/App/lib/core/Gen/StructGenMixin.vp @@ -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