Some simple information syncing

This commit is contained in:
2026-07-28 21:08:58 +08:00
parent 1837339f69
commit 3633be1995
65 changed files with 1132 additions and 368581 deletions

View File

@@ -2045,6 +2045,21 @@ class ExprCallHandle(BaseHandle):
arg = Gen.builder.sext(arg, ir.IntType(64), name=f"sext_vararg_{FuncName}")
else:
arg = Gen.builder.zext(arg, ir.IntType(64), name=f"zext_vararg_{FuncName}")
elif isinstance(arg.type, (ir.LiteralStructType, ir.IdentifiedStructType)):
# 治本修复:变参函数(如 printf不支持 struct by value 传递。
# 当 self 等 struct 值被错误地 load 为值(而非指针)传入变参时,
# ABI 不匹配会导致崩溃。修复:将 struct 值通过 alloca + bitcast
# 转换为 i8* 指针传递,确保与 %p / %s 等格式说明符兼容。
try:
alloca_tmp = Gen.builder.alloca(arg.type, name=f"vararg_struct_{FuncName}_{i}")
Gen.builder.store(arg, alloca_tmp)
arg = Gen.builder.bitcast(alloca_tmp, ir.IntType(8).as_pointer(), name=f"vararg_struct_ptr_{FuncName}_{i}")
except Exception:
# 回退alloca/store 失败时,尝试 ptrtoint 为 i64
try:
arg = Gen.builder.ptrtoint(arg, ir.IntType(64), name=f"vararg_struct_i64_{FuncName}_{i}")
except Exception:
pass # 最终回退:保留原值(可能仍会导致崩溃,但至少不阻塞编译)
adjusted.append(arg)
result = Gen.builder.call(func, adjusted, name=f"call_{FuncName}")
else:
@@ -2851,15 +2866,33 @@ class ExprCallHandle(BaseHandle):
if class_sha1 and ClassName in Gen.structs:
struct_type = Gen.structs[ClassName]
self_ptr_type = ir.PointerType(struct_type)
param_types = [self_ptr_type] + [a.type for a in CallArgs]
func_type = ir.FunctionType(ir.IntType(32), param_types)
# 修复 Bug 4: 从符号表获取完整参数列表(含默认参数)和正确返回类型,
# 而非仅使用 CallArgs漏掉默认参数和硬编码 i32 返回类型。
# 这避免了 main.py 中 declare Logger.info(...,i8*) 2参数
# 与 VLogger 中 define Logger.info(...,i8*,i8*) 3参数的签名冲突。
ret_type: Any = ir.IntType(32)
param_types: list[Any] = [self_ptr_type] + [a.type for a in CallArgs]
SymInfoFallback = self.LookupFunctionSymbol(MethodName, module_path=ClassName)
if SymInfoFallback and SymInfoFallback.IsFunction:
sig = self.BuildLLVMFuncTypeFromSig(SymInfoFallback, Gen)
if sig is not None:
sig_ret, sig_params, _ = sig
ret_type = sig_ret
is_static_fb = FuncMeta.STATIC_METHOD in SymInfoFallback.MetaList
if not is_static_fb:
sig_params = [self_ptr_type] + sig_params
param_types = sig_params
func_type = ir.FunctionType(ret_type, param_types)
func = ir.Function(Gen.module, func_type, name=FullMethodName)
Gen.functions[FullMethodName] = func
if isinstance(ObjVal.type, ir.PointerType) and ObjVal.type.pointee == struct_type:
call_self = ObjVal
else:
call_self = Gen.builder.bitcast(ObjVal, self_ptr_type, name=f"method_self_{ClassName}")
adjusted = Gen._adjust_args([call_self] + CallArgs, func)
call_args_fb = [call_self] + CallArgs
self._fill_default_args(call_args_fb, func, FullMethodName)
self._append_eh_msg_out_arg(call_args_fb, func, Gen)
adjusted = Gen._adjust_args(call_args_fb, func)
result = Gen.builder.call(func, adjusted, name=f"call_{FullMethodName}")
return result
raise Exception(f"Undefined method '{MethodName}' in class '{ClassName}' (no function declaration found for '{FullMethodName}')")