From a9d71714b31e51890273f52245f62791ee37bcef Mon Sep 17 00:00:00 2001 From: TermiNexus Date: Tue, 25 Aug 2026 17:51:21 +0800 Subject: [PATCH] =?UTF-8?q?fix(callgenmixin):=20=E5=AD=97=E9=9D=A2?= =?UTF-8?q?=E9=87=8F=200=20=E6=94=B9=20t.CSizeT(0)=E2=80=94=E2=80=94?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20i32=20=E5=AE=9E=E5=8F=82=E4=B8=8E=20i64=20?= =?UTF-8?q?=E5=BD=A2=E5=8F=82=E4=B8=8D=E4=B8=80=E8=87=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 根因(反汇编实锤):空参数构造走 can==0 分支,字面量 0 是 i32,生成 IR call 实参 i32 与 declare i64 不一致 → llc 按 i32 生成 movl(4 字节写 can 槽)→ i64 形参高 4 字节残留垃圾 → callee 读 can=[垃圾][count]。StringIterTest can=0x2B2_... 崩溃根因。 修复:三处 _translate_struct_ctor(..., cargs, 0, trans) 字面量 0 → t.CSizeT(0)(i64),IR 实参与 declare 一致 → llc movq 写 8 字节。 --- App/lib/core/Gen/CallGenMixin.vp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/App/lib/core/Gen/CallGenMixin.vp b/App/lib/core/Gen/CallGenMixin.vp index 4a1909b..fa14a5d 100644 --- a/App/lib/core/Gen/CallGenMixin.vp +++ b/App/lib/core/Gen/CallGenMixin.vp @@ -313,7 +313,7 @@ class CallGenMixin(CallGenBase.CallGenBase): ctor_is_oop = gen_ctor_entry.IsOOP if ctor_is_oop != 0: return self.Gen.CallGenCtor._translate_struct_ctor( - pool, builder, mod, struct_ty, func_name, cargs, 0, trans) + pool, builder, mod, struct_ty, func_name, cargs, t.CSizeT(0), trans) # @t.NoVTable 类(无方法、类语义/指针对象):无参构造也应分配内存 # 返回指针。否则按值结构体返回 ConstZero(struct_ty),LHS 联合注解 # (如 Plain|CPtr)存 0 指针 → p.v 解引用 NULL 段错误 @@ -323,7 +323,7 @@ class CallGenMixin(CallGenBase.CallGenBase): ctor_is_novt = gen_ctor_entry.IsNoVTable if ctor_is_novt != 0: return self.Gen.CallGenCtor._translate_struct_ctor( - pool, builder, mod, struct_ty, func_name, cargs, 0, trans) + pool, builder, mod, struct_ty, func_name, cargs, t.CSizeT(0), trans) # 普通结构体:检查是否有默认值(用 entry 直接访问) gen_has_defaults: int = 0 if gen_ctor_entry is not None: @@ -338,7 +338,7 @@ class CallGenMixin(CallGenBase.CallGenBase): if gen_has_defaults == 1: # 有默认值:走构造函数路径应用默认值 return self.Gen.CallGenCtor._translate_struct_ctor( - pool, builder, mod, struct_ty, func_name, cargs, 0, trans) + pool, builder, mod, struct_ty, func_name, cargs, t.CSizeT(0), trans) # 无默认值:返回 zeroinitializer ret: llvmlite.Value | t.CPtr = llvmlite.ConstZero(pool, struct_ty) return ret @@ -1254,7 +1254,7 @@ class CallGenMixin(CallGenBase.CallGenBase): # 检查被调用函数是否为变长函数(*args),若是则对变长参数进行 C ABI 提升 # (cargs 为本函数参数 AST 链表,self_offset=0 普通函数调用) is_variadic_call: int = self.Gen.CallGenVa._check_and_promote_variadic_call( - pool, builder, mod, call_name, head, can, cargs, 0, trans) + pool, builder, mod, call_name, head, can, cargs, t.CSizeT(0), trans) # try-except:被调函数带 EH 输出参数时,追加输出实参 + 调用后检测异常 return self.Gen.CallGenLeafKit._emit_eh_guarded_call( builder, pool, mod, trans, found_func, call_name, head, can,