fix(gen): this-adjust 基类 bitcast 前确保 opaque 类型声明

_translate_method_call/_translate_super_call 的多继承字节偏移调整会生成
bitcast i8* -> %SHA1.ClassGenBase*,但 PrintModule 只扫描函数签名、
不扫函数体指令,跨模块基类类型未被声明导致 llc 报 use of undefined type。
在 bitcast 前调用 module_ensure_opaque_for_type(幂等,仅对未定义类型
添加 = type opaque)。
This commit is contained in:
TermiNexus committed 2026-08-19 06:25:33 +08:00
1 parent e8a3fd0a65
commit eb0398eae3
1 file changed
+8
+8
View File
@@ -989,6 +989,11 @@ class CallGenCall(CallGenBase.CallGenBase):
builder, i8_ty_th, obj_i8_th, delta_val_th)
if adj_th is not None:
anc_ptr_ty_th: llvmlite.LLVMType | t.CPtr = llvmlite.Ptr(pool, anc_entry_th.Ty)
# 跨模块基类(如 Generator → ClassGenBase)的完整定义不在本模块,
# bitcast 引用 %"sha1.ClassGenBase" 前必须确保 opaque 声明存在,
# 否则 llc 报 "use of undefined type"(PrintModule 只扫函数签名,
# 函数体内的 bitcast 类型不会被自动声明)。
llvmlite.module_ensure_opaque_for_type(mod, pool, anc_ptr_ty_th)
self_arg = llvmlite.build_bitcast(builder, adj_th, anc_ptr_ty_th)
# 构建参数链表: self → arg1 → arg2 → ...
llvmlite.value_set_next(self_arg, None)
@@ -1324,6 +1329,9 @@ class CallGenCall(CallGenBase.CallGenBase):
builder, i8_ty_sp, obj_i8_sp, dval_sp)
if adj_sp is not None:
anc_ptr_sp: llvmlite.LLVMType | t.CPtr = llvmlite.Ptr(pool, anc_entry_sp.Ty)
# 同上:跨模块祖先类型 bitcast 前确保 opaque 声明,
# 否则 llc 报 "use of undefined type"
llvmlite.module_ensure_opaque_for_type(mod, pool, anc_ptr_sp)
self_arg = llvmlite.build_bitcast(builder, adj_sp, anc_ptr_sp)
# 4. 查找父类方法函数 + 构造调用名(SHA1 mangled)
anc_lookup: str = pool.alloc(160)