fix(tpv): void 函数 return <expr> 丢弃值 + ret void(llc ret i32 vs define void)

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 <expr> 仅求值丢弃 + ret void(Python 语义)。
This commit is contained in:
TermiNexus committed 2026-08-29 11:12:23 +08:00
1 parent b7eeb504ee
commit efc8f7948f
1 file changed
+12
+12
View File
@@ -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 <expr>:丢弃值 + 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)