fix(exprcall): NoVTable 跨 Mixin self. 调用按定义类解析 + this 前移
缺陷(TPV bootstrap 的 undefined symbol: <sha1>.StmtGenDeclMixin.translate_return 同根因):NoVTable 多继承下,BaseB.caller 内 self.helper()(helper 定义在兄弟 Mixin BaseA,经 Combined(BaseA, BaseB) 组合)被 mangle 成 BaseB.helper —— 用 调用者类做前缀,而定义符号是 BaseA.helper -> ld.lld undefined symbol。 修复(HandlesExprCall.py): 1. 调用端 MRO 回退失败后,全局扫描已注册类找方法定义类(兄弟 Mixin 兜底); 2. _adjust_this_for_inherited_method 支持"调用类不含定义类字段"场景: this 按组合布局前移 sizeof(定义类 struct)(BaseB* -> BaseA*)。 新增 Test/NoVTableCrossMixinTest 回归(caller()==42 通过),TestsOverview 记录。
This commit is contained in:
1 parent
015d5c38ea
commit
bd5d2467ab
4 files changed
+117
-1
No files matched your search
@@ -2529,7 +2529,23 @@ class ExprCallHandle(BaseHandle):
|
||||
return ObjVal
|
||||
sub_off: int | None = self._compute_field_byte_offset(Gen, ClassName, first_field_name)
|
||||
if sub_off is None:
|
||||
return ObjVal
|
||||
# 兄弟 Mixin 场景:调用类(ClassName)不含定义类字段——定义类在
|
||||
# 组合类 MRO 中位于调用类之前(如 Combined(BaseA, BaseB),BaseB 内
|
||||
# self.helper() 调 BaseA.helper)。此时 BaseB.this 指向组合类中
|
||||
# BaseB 字段区起点,BaseA 区在它前面,this 前移 sizeof(定义类 struct)。
|
||||
anc_st: Any = Gen.structs.get(method_anc) or Gen.structs.get(anc_lookup)
|
||||
if not anc_st or not isinstance(anc_st, ir.IdentifiedStructType) or anc_st.elements is None:
|
||||
return ObjVal
|
||||
sibling_delta: int = -Gen._get_struct_size(anc_st)
|
||||
if sibling_delta >= 0:
|
||||
return ObjVal
|
||||
obj_i8_s: ir.Value = Gen.builder.bitcast(
|
||||
ObjVal, ir.PointerType(ir.IntType(8)), name=f"this_sibling_i8_{anc_lookup}")
|
||||
adj_s: ir.Value = Gen.builder.gep(
|
||||
obj_i8_s, [ir.Constant(ir.IntType(64), sibling_delta)],
|
||||
name=f"this_sibling_{anc_lookup}")
|
||||
return Gen.builder.bitcast(adj_s, ir.PointerType(anc_st),
|
||||
name=f"this_sibling_cast_{anc_lookup}")
|
||||
anc_off: int | None = self._compute_field_byte_offset(Gen, method_anc, first_field_name)
|
||||
if anc_off is None:
|
||||
return ObjVal
|
||||
@@ -3148,6 +3164,25 @@ class ExprCallHandle(BaseHandle):
|
||||
if func:
|
||||
method_anc = anc
|
||||
break
|
||||
if not func or len(list(func.blocks)) == 0:
|
||||
# 兄弟 Mixin 兜底:方法不在本类 MRO 链(如 BaseB 内 self.helper()
|
||||
# 调兄弟 BaseA.helper,BaseB 自身无 BaseA 的继承信息)。全局扫描
|
||||
# 已注册类找定义类,this 由 _adjust_this_for_inherited_method 按
|
||||
# 组合布局前移 sizeof(定义类 struct)。修复 TPC 编译 TPV 的
|
||||
# undefined symbol: <sha1>.BaseB.helper / StmtGenDeclMixin.translate_*。
|
||||
for _cand_cls, _cand_methods in list(Gen.class_methods.items()):
|
||||
if _cand_cls == ClassName:
|
||||
continue
|
||||
if not any(_cm.endswith(f'.{MethodName}') or _cm == MethodName for _cm in _cand_methods):
|
||||
continue
|
||||
_cand_full = f'{_cand_cls}.{MethodName}'
|
||||
_cand_func = Gen._find_function(_cand_full)
|
||||
if not _cand_func:
|
||||
_cand_func = Gen._find_function(f'{_cand_full}__')
|
||||
if _cand_func:
|
||||
func = _cand_func
|
||||
method_anc = _cand_cls
|
||||
break
|
||||
if func:
|
||||
# 多继承 this 调整:继承方法定义在无 vtable 父类且字段区偏移 > 0 时,
|
||||
# 把 self 定位到父类第一个用户字段在子类中的位置并 bitcast 成父类指针。
|
||||
|
||||
Reference in new issue
Block a user