From 5460d78ff19c564fd2458310cf4dc71b3dde873f Mon Sep 17 00:00:00 2001 From: TermiNexus Date: Thu, 15 Oct 2026 23:11:24 +0800 Subject: [PATCH] =?UTF-8?q?fix(gi):=20=E6=A8=A1=E5=9D=97=E7=BA=A7=E7=B1=BB?= =?UTF-8?q?=E5=85=A8=E5=B1=80=E6=8C=89=E5=80=BC=E6=9C=AC=E4=BD=8D=E5=AD=98?= =?UTF-8?q?=E5=82=A8(=E4=BB=85=20=5F=5Fnew=5F=5F=20=E7=B1=BB=E7=94=A8?= =?UTF-8?q?=E6=8C=87=E9=92=88)=20-=20=E4=BF=AE=20CAM:=20V3=20=E8=A2=AB?= =?UTF-8?q?=E5=8C=85=E6=88=90=20Ptr=20=E8=87=B4=E6=82=AC=E5=9E=82=E8=AF=AF?= =?UTF-8?q?=E6=8A=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App/lib/Stub/StubGen/VpiReader.vp | 6 +++--- App/lib/core/Gen/TranslatorGenMixin.vp | 9 ++++++++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/App/lib/Stub/StubGen/VpiReader.vp b/App/lib/Stub/StubGen/VpiReader.vp index 08b4ea1..6dcb107 100644 --- a/App/lib/Stub/StubGen/VpiReader.vp +++ b/App/lib/Stub/StubGen/VpiReader.vp @@ -2885,10 +2885,10 @@ def _inject_global_variable_declare(pool: memhub.MemBuddy*, mod: mlirlite.LLVMMo gv_ty_v: mlirlite.LLVMType* = resolved_v match resolved_v: case mlirlite.LLVMType.Struct(_, _, _): - # Object classes (@t.Object/@t.CVTable: object-as-pointer) -> Ptr(struct), matching - # handle_module_level_var; plain t.CStruct value classes keep a value instance. + # 与 handle_module_level_var 保持同一口径:只有 `__new__`(自定义分配)的类才以指针表示; + # 仅"有方法 / 带 vtable"(IsOOP / HasVTable)的类,模块级全局同样按值本位存储。 gv_entry_v: GenTypes.StructEntry* = GenApi.find_struct_by_type(resolved_v) - if gv_entry_v is not None and (gv_entry_v.HasNew != 0 or gv_entry_v.HasVTable != 0 or gv_entry_v.IsOOP != 0): gv_ty_v = mlirlite.Ptr(pool, resolved_v) + if gv_entry_v is not None and gv_entry_v.HasNew != 0: gv_ty_v = mlirlite.Ptr(pool, resolved_v) else: gv_ty_v = resolved_v case mlirlite.LLVMType.Array(aelem_v, acount_v): # Fixed-size arrays (CArray[T, N]) keep the full [N x T] type, matching diff --git a/App/lib/core/Gen/TranslatorGenMixin.vp b/App/lib/core/Gen/TranslatorGenMixin.vp index d538e26..6b9053c 100644 --- a/App/lib/core/Gen/TranslatorGenMixin.vp +++ b/App/lib/core/Gen/TranslatorGenMixin.vp @@ -556,7 +556,14 @@ novirtual class TranslatorGenMixin: gv_hn = gv_entry.HasNew; gv_hv = gv_entry.HasVTable; gv_oo = gv_entry.IsOOP stdio.printf("[GVAR-DIAG] name=%s hasnew=%d hasvtable=%d isoop=%d\n", var_name, gv_hn, gv_hv, gv_oo) - if gv_entry is not None and (gv_entry.HasNew != 0 or gv_entry.HasVTable != 0 or gv_entry.IsOOP != 0): + if gv_entry is not None and gv_entry.HasNew != 0: + # 只有定义了 `__new__`(自定义分配器,对象存储可能不在本帧)的类才**必须** + # 以指针表示。仅"有方法 / 带 vtable"(IsOOP / HasVTable)的类,值本体内联 + # 存储同样可工作(方法调用把 &obj 作 self 传入,vptr 亦可内联在值里), + # 因此模块级全局也按**值本位**存储,与局部变量(`alloca %T`)语义一致: + # `CAM: V3` ⇒ `@CAM = global %V3`,`CAM = V3(...)` 即整块就地写入 + # (不再产生"把本帧对象地址存进全局"的悬垂,也不再让 + # check_return_frame_decl 误报 LifetimeError)。 # Object-class global (object-as-pointer): remember the Struct value type # so a BSS storage global can hold the instance; otherwise @g is NULL. resolved_stg_ty = resolved