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