fix(coro): 帧结构体定义输出到 IR,修复 GEP base element must be sized
协程帧类型 %Coro_<name> 只存 _coro_frame_types 未注册进 Gen.structs, StructGen.finalize 不输出其定义 → resume_<name> 的 GEP 引用 opaque 类型,opt ASan 插桩报 "base element of getelementptr must be sized"。 修复:_GetOrCreateFrameType 注册帧到 Gen.structs;finalize 追加 _coro_frame_types 兜底输出(防 _generate_structs 清空时丢定义)。
This commit is contained in:
1 parent
13a8f6c1b6
commit
a775ec9932
2 files changed
+13
No files matched your search
@@ -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
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in new issue
Block a user