From c979f0f94dad40e23f4aa1ecc39c0c40dadd00c4 Mon Sep 17 00:00:00 2001 From: TermiNexus Date: Fri, 21 Aug 2026 14:20:51 +0800 Subject: [PATCH] =?UTF-8?q?fix(coro):=20M3=20=E4=B8=89=E5=A4=84=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E2=80=94=E2=80=94nonlocal=20=E9=97=AD=E5=8C=85?= =?UTF-8?q?=E3=80=81wake=20=E7=A9=BA=E5=9D=97=E7=BB=88=E6=AD=A2=E3=80=81co?= =?UTF-8?q?ro=5Frun=20=E5=94=A4=E9=86=92=E6=A7=BD=E6=8C=89=E7=B4=A2?= =?UTF-8?q?=E5=BC=95=E5=AE=9A=E4=BD=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - _PreScanExtraSlots 内嵌 _walk 闭包变量需 nonlocal(UnboundLocalError) - coro_run wake_due_bb 补 br loop(空块导致 opt ASan 插桩解析失败) - coro_run 内联在 main 翻译时 _coro_wake_ptr 已被恢复为 None,改为按 _coro_slot_vars 索引定位 __coro_wake_us 槽 - 验证:CoroTest ASan 模式编译+运行通过,coro result = 15 --- lib/core/Handles/HandlesAsyncFunctions.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/core/Handles/HandlesAsyncFunctions.py b/lib/core/Handles/HandlesAsyncFunctions.py index 00699c7..110a6af 100644 --- a/lib/core/Handles/HandlesAsyncFunctions.py +++ b/lib/core/Handles/HandlesAsyncFunctions.py @@ -261,6 +261,7 @@ class AsyncFunctionHandle(BaseHandle): uses_sleep: list[bool] = [False] def _walk(stmts: list[ast.stmt]) -> None: + nonlocal await_counter, for_counter for stmt in stmts: if isinstance(stmt, (ast.If, ast.While)): _walk(stmt.body) @@ -951,8 +952,16 @@ class AsyncFunctionHandle(BaseHandle): Gen.builder.cbranch(done_cond, after_bb, check_bb) # SUSPEND:若 coro_sleep 唤醒槽存在且未到点,Sleep(1) 后继续轮询 Gen.builder.position_at_start(check_bb) - wake_ptr: ir.Value | None = getattr(Gen, '_coro_wake_ptr', None) - if wake_ptr is not None: + wake_idx: int | None = None + slot_vars: list[str] = getattr(Gen, '_coro_slot_vars', {}).get(async_name, []) + if '__coro_wake_us' in slot_vars: + wake_idx = 3 + slot_vars.index('__coro_wake_us') + if wake_idx is not None: + wake_ptr: ir.Value = Gen.builder.gep( + frame_ptr, + [ir.Constant(ir.IntType(32), 0), ir.Constant(ir.IntType(32), wake_idx)], + name='coro_wake_ptr', + ) wake_val: ir.Value = Gen._load(wake_ptr, name='coro_wake') now_fn: ir.Function = self._GetWinFunc('GetTickCount64', Gen, ir.IntType(64)) now_val: ir.Value = Gen.builder.call(now_fn, [], name='tick_now') @@ -965,6 +974,7 @@ class AsyncFunctionHandle(BaseHandle): Gen.builder.call(sleep_fn, [ir.Constant(ir.IntType(32), 1)]) Gen.builder.branch(loop_bb) Gen.builder.position_at_start(wake_due_bb) + Gen.builder.branch(loop_bb) else: Gen.builder.branch(loop_bb) Gen.builder.position_at_start(after_bb)