From a775ec9932841d36b50d2a427b7bce63f5030b3c Mon Sep 17 00:00:00 2001 From: TermiNexus Date: Fri, 21 Aug 2026 12:41:10 +0800 Subject: [PATCH] =?UTF-8?q?fix(coro):=20=E5=B8=A7=E7=BB=93=E6=9E=84?= =?UTF-8?q?=E4=BD=93=E5=AE=9A=E4=B9=89=E8=BE=93=E5=87=BA=E5=88=B0=20IR?= =?UTF-8?q?=EF=BC=8C=E4=BF=AE=E5=A4=8D=20GEP=20base=20element=20must=20be?= =?UTF-8?q?=20sized?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 协程帧类型 %Coro_ 只存 _coro_frame_types 未注册进 Gen.structs, StructGen.finalize 不输出其定义 → resume_ 的 GEP 引用 opaque 类型,opt ASan 插桩报 "base element of getelementptr must be sized"。 修复:_GetOrCreateFrameType 注册帧到 Gen.structs;finalize 追加 _coro_frame_types 兜底输出(防 _generate_structs 清空时丢定义)。 --- lib/core/Handles/HandlesAsyncFunctions.py | 1 + lib/core/LLVMCG/StructGen.py | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/lib/core/Handles/HandlesAsyncFunctions.py b/lib/core/Handles/HandlesAsyncFunctions.py index 949247b..b475404 100644 --- a/lib/core/Handles/HandlesAsyncFunctions.py +++ b/lib/core/Handles/HandlesAsyncFunctions.py @@ -146,6 +146,7 @@ class AsyncFunctionHandle(BaseHandle): frame_ty: ir.IdentifiedStructType = ir.IdentifiedStructType(Gen.module, f'Coro_{name}') frame_ty.set_body(*fields) Gen._coro_frame_types[name] = frame_ty + Gen.structs[f'Coro_{name}'] = frame_ty Gen._coro_local_vars[name] = local_names return frame_ty diff --git a/lib/core/LLVMCG/StructGen.py b/lib/core/LLVMCG/StructGen.py index f6eb280..a705710 100644 --- a/lib/core/LLVMCG/StructGen.py +++ b/lib/core/LLVMCG/StructGen.py @@ -168,6 +168,18 @@ class StructGenMixin: else: struct_defs.append(f'{sname_ir} = type {{ {elems} }}') struct_names.add(sname) + # 协程帧结构体兜底(M1):帧注册进 Gen.structs 时上面已输出; + # 未注册(被 _generate_structs 清空)时这里补齐定义,避免 + # getelementptr base element must be sized。 + coro_frames: dict = getattr(self, '_coro_frame_types', None) or {} + for _cf_name, _cf_ty in coro_frames.items(): + if _cf_name in struct_names: + continue + if isinstance(_cf_ty, ir.IdentifiedStructType) and _cf_ty.elements: + _cf_sname: str = _cf_ty.name + _cf_ir: str = f'%"{_cf_sname}"' if (_cf_sname[0].isdigit() or "." in _cf_sname) else f'%{_cf_sname}' + struct_defs.append(f'{_cf_ir} = type {{ {", ".join(str(e) for e in _cf_ty.elements)} }}') + struct_names.add(_cf_sname) if struct_defs: lines: list[str] = ir_text.split('\n') # 预计算全部 "= type" 定义行前缀(一次性),用 str.startswith(tuple)