From efc8f7948f19f770d8440af8fd0f3439758dd3a7 Mon Sep 17 00:00:00 2001 From: TermiNexus Date: Sat, 29 Aug 2026 11:12:23 +0800 Subject: [PATCH] =?UTF-8?q?fix(tpv):=20void=20=E5=87=BD=E6=95=B0=20return?= =?UTF-8?q?=20=20=E4=B8=A2=E5=BC=83=E5=80=BC=20+=20ret=20void?= =?UTF-8?q?=EF=BC=88llc=20ret=20i32=20vs=20define=20void=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit GenApi.add_global_name 声明 -> None 但 body 为 return g.TranslatorGen.add_global_name(...)(委托返回 i32)→ translate_return 对带值 return 直接 build_ret(val) 生成 ret i32,与 define void 冲突 → llc 'value doesn't match function result type void'。修复:函数返回类型为 void 时 return 仅求值丢弃 + ret void(Python 语义)。 --- App/lib/core/Gen/Stmt/StmtGenCifMixin.vp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/App/lib/core/Gen/Stmt/StmtGenCifMixin.vp b/App/lib/core/Gen/Stmt/StmtGenCifMixin.vp index c7714c9..3689896 100644 --- a/App/lib/core/Gen/Stmt/StmtGenCifMixin.vp +++ b/App/lib/core/Gen/Stmt/StmtGenCifMixin.vp @@ -602,6 +602,18 @@ class StmtGenCifMixin: ret_ty_rt: llvmlite.LLVMType | t.CPtr = None if cur_func_rt is not None and val is not None and val.Ty is not None: ret_ty_rt = llvmlite.function_get_ret_ty(cur_func_rt) + # void 函数 return :丢弃值 + ret void(Python 语义合法;此前 + # 直接 build_ret(val) 生成 ret i32 与 define void 冲突 → llc "value + # doesn't match function result type 'void'"——GenApi.add_global_name + # `return g.TranslatorGen.add_global_name(...)` 委托调用根因)。 + if ret_ty_rt is not None and val is not None: + rv_void: int = 0 + match ret_ty_rt: + case llvmlite.LLVMType.Void(): + rv_void = 1 + if rv_void != 0: + llvmlite.build_ret_void(builder) + return 0 if ret_ty_rt is not None: val_bits: int = self.Gen.ExprGenBase.get_llvm_type_bits(val.Ty) ret_bits: int = self.Gen.ExprGenBase.get_llvm_type_bits(ret_ty_rt)