fix(gen): 异常与传播出口也释放 slife(P1)

插桩点选在 StmtGenMixin._eh_ret_default —— 异常路径上真正离开函数的唯一汇聚点(translate_raise 的 bare raise / StopIteration / 传播三条分支 + try 的 UnhandledBB 传播分支都走它),发 ret 前 _SlifeEmitFrees。不得改在 raise 语句本身:被本函数 except 捕获时对象仍在用(那一步只 br 到 DispatchBB);EH 返回值也不会是 slife 对象(逃逸检查已拒)。
This commit is contained in:
TermiNexus committed 2026-10-08 21:04:33 +08:00
1 parent 70390858d8
commit b6a9b50f93
1 file changed
+5
+5
View File
@@ -466,6 +466,11 @@ novirtual class StmtGenMixin(StmtGenDeclMixin.StmtGenDeclMixin):
if cur_func is None: return 0
ret_ty: mlirlite.LLVMType* = mlirlite.function_get_ret_ty(cur_func)
if ret_ty is None: return 0
# P1:异常/传播出口**也是函数出口** —— 这里是"异常路径上真正离开函数"的唯一落点
# (translate_raise 的三条分支 + try 的 UnhandledBB 传播分支都汇聚到它),所以在此逆序释放
# 本函数登记的 slife。**不能**改在 raise 语句本身释放:被本函数 except 捕获时对象仍在用
# (那一步只 br 到 DispatchBB,不走这里);同理 EH 返回值不会是 slife 对象(逃逸检查已拒)。
self.Gen.VarGen._SlifeEmitFrees(pool, builder, trans.Module, trans)
match ret_ty:
case mlirlite.LLVMType.Void():
mlirlite.build_ret_void(builder)