From 609635c73e23302c255f54e3a950c4716938eac8 Mon Sep 17 00:00:00 2001 From: TermiNexus Date: Sat, 22 Aug 2026 01:25:12 +0800 Subject: [PATCH] =?UTF-8?q?fix(tpv):=20=E5=B8=A7=E6=B1=A0=E8=AE=BF?= =?UTF-8?q?=E9=97=AE=E6=94=B9=20Value=20=E8=A7=86=E5=9B=BE=20+=20ConstNull?= =?UTF-8?q?=20=E8=A1=A5=20name=20=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - GlobalVariable 非 Value 子类,create/destroy 直接 build_load/store 按 Value 布局读字段错位(Ty 读到 void、Name 为空)→ 生成 "load i64, void" 非法 IR;改构造 SSAValue(Ty=Ptr(i64), Name="@coro_pool_") 视图 - ConstNull 签名 (pool, ty, name),6 处漏传 name → v.Name=None → "store i8* (None), i8**" 非法 IR;全部补 "null" --- App/lib/core/Gen/AsyncGenMixin.vp | 34 +++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/App/lib/core/Gen/AsyncGenMixin.vp b/App/lib/core/Gen/AsyncGenMixin.vp index 7eb8afa..d7137d8 100644 --- a/App/lib/core/Gen/AsyncGenMixin.vp +++ b/App/lib/core/Gen/AsyncGenMixin.vp @@ -831,8 +831,14 @@ class AsyncGenMixin(CallGenBase.CallGenBase): # M7 帧池:i64 池头(0 = 空);帧首 8 字节存 next(覆盖 state/done,弹池后统一清零) pool_gv: llvmlite.GlobalVariable | t.CPtr = self._get_coro_pool( pool, mod, trans, name) + # GlobalVariable 非 Value 子类:构造 Value 视图(Ty=Ptr(i64), Name="@coro_pool_") + pool_ref_name: str = pool.alloc(96) + if pool_ref_name is not None: + viperlib.snprintf(pool_ref_name, 96, "@coro_pool_%s", name) + pool_ref: llvmlite.Value | t.CPtr = llvmlite.SSAValue( + pool, i64_ptr_ty, pool_ref_name) pool_head: llvmlite.Value | t.CPtr = llvmlite.build_load( - builder, i64_ty, pool_gv) + builder, i64_ty, pool_ref) if pool_head is None: return 0 zero64: llvmlite.Value | t.CPtr = llvmlite.const_int64(pool, 0) @@ -857,7 +863,7 @@ class AsyncGenMixin(CallGenBase.CallGenBase): builder, i64_ty, node_next_ptr) if next_head is None: return 0 - llvmlite.build_store(builder, next_head, pool_gv) + llvmlite.build_store(builder, next_head, pool_ref) hit_frame: llvmlite.Value | t.CPtr = llvmlite.build_inttoptr( builder, pool_head, frame_ptr_ty) if hit_frame is None: @@ -892,7 +898,7 @@ class AsyncGenMixin(CallGenBase.CallGenBase): if frame_ref is None: return 0 zero: llvmlite.Value | t.CPtr = llvmlite.const_int32(pool, 0) - null_p: llvmlite.Value | t.CPtr = llvmlite.ConstNull(pool, i8_ptr_ty) + null_p: llvmlite.Value | t.CPtr = llvmlite.ConstNull(pool, i8_ptr_ty, "null") si: int = 0 for si in range(5): if si == 4: @@ -2208,15 +2214,21 @@ class AsyncGenMixin(CallGenBase.CallGenBase): # 回池:帧首 8 字节存旧池头;池头 = 本帧(i64) pool_gv: llvmlite.GlobalVariable | t.CPtr = self._get_coro_pool( pool, mod, trans, async_name) - pool_head: llvmlite.Value | t.CPtr = llvmlite.build_load( - builder, i64_ty, pool_gv) + # GlobalVariable 非 Value 子类:构造 Value 视图(Ty=Ptr(i64), Name="@coro_pool_") i64_ptr_ty: llvmlite.LLVMType | t.CPtr = llvmlite.Ptr(pool, i64_ty) + pool_ref_name: str = pool.alloc(96) + if pool_ref_name is not None: + viperlib.snprintf(pool_ref_name, 96, "@coro_pool_%s", async_name) + pool_ref: llvmlite.Value | t.CPtr = llvmlite.SSAValue( + pool, i64_ptr_ty, pool_ref_name) + pool_head: llvmlite.Value | t.CPtr = llvmlite.build_load( + builder, i64_ty, pool_ref) node_next: llvmlite.Value | t.CPtr = llvmlite.build_bitcast( builder, frame_ptr, i64_ptr_ty) llvmlite.build_store(builder, pool_head, node_next) frame_i64: llvmlite.Value | t.CPtr = llvmlite.build_ptrtoint( builder, frame_ptr, i64_ty) - llvmlite.build_store(builder, frame_i64, pool_gv) + llvmlite.build_store(builder, frame_i64, pool_ref) return llvmlite.const_int32(pool, 0) def translate_coro_exception(self, builder: llvmlite.IRBuilder | t.CPtr, @@ -2257,23 +2269,23 @@ class AsyncGenMixin(CallGenBase.CallGenBase): i8_ptr_ty: llvmlite.LLVMType | t.CPtr = llvmlite.Ptr( pool, llvmlite.Int8(pool)) if cl is None or trans is None or cl.args is None or len(cl.args) < 1: - return llvmlite.ConstNull(pool, i8_ptr_ty) + return llvmlite.ConstNull(pool, i8_ptr_ty, "null") async_name: str = self._var_to_async(trans, cl.args.get(0)) if async_name is None: - return llvmlite.ConstNull(pool, i8_ptr_ty) + return llvmlite.ConstNull(pool, i8_ptr_ty, "null") frame_ty: llvmlite.LLVMType | t.CPtr = self._lookup_coro_frame( trans, async_name) if frame_ty is None: - return llvmlite.ConstNull(pool, i8_ptr_ty) + return llvmlite.ConstNull(pool, i8_ptr_ty, "null") frame_ptr_ty: llvmlite.LLVMType | t.CPtr = llvmlite.Ptr(pool, frame_ty) frame_val: llvmlite.Value | t.CPtr = self.Gen.ExprGen.translate_value( builder, pool, mod, cl.args.get(0), None, 0, trans) if frame_val is None: - return llvmlite.ConstNull(pool, i8_ptr_ty) + return llvmlite.ConstNull(pool, i8_ptr_ty, "null") frame_ptr: llvmlite.Value | t.CPtr = llvmlite.build_bitcast( builder, frame_val, frame_ptr_ty) if frame_ptr is None: - return llvmlite.ConstNull(pool, i8_ptr_ty) + return llvmlite.ConstNull(pool, i8_ptr_ty, "null") msg_ptr: llvmlite.Value | t.CPtr = llvmlite.build_gep_struct( builder, frame_ty, i8_ptr_ty, frame_ptr, 4) return llvmlite.build_load(builder, i8_ptr_ty, msg_ptr)