feat(lifetime): 构造器路径填 recv_life——裸 T() 构造(入口块 alloca)算 FRAME
_translate_struct_ctor 两份副本都算 recv_life_ct:_g_new_storage == None(无 new 描述符提供存储)→ 裸 T() 的存储是入口块 alloca → LIFE_FRAME(参与构造器同命裁剪);非空(存储来自 new …)→ -1 不裁剪。 两处 __init__ 调用点(:171 / :675)均传入。覆盖 CtorHolder(&l) / BoxCtor(&l) 这类裸构造误报。
This commit is contained in:
1 parent
357a8bba05
commit
953c829e9f
1 file changed
+12
-2
@@ -82,6 +82,11 @@ novirtual class CallGenCtor(CallGenBase.CallGenBase):
|
||||
tmp: mlirlite.Value* = _g_new_storage
|
||||
if tmp is None: tmp = self.Gen.VarGen._alloca_at_entry(builder, struct_ty)
|
||||
if tmp is None: return mlirlite.ConstZero(pool, struct_ty)
|
||||
# 构造器同命裁剪用:被构造对象的生命期。
|
||||
# 裸 `T()`(没有 `new` 描述符提供存储)= 入口块 alloca → **FRAME**;
|
||||
# 存储来自 `new …`(_g_new_storage 非空)时来源/生命期由**上游**决定,这里不猜 → -1(不裁剪)。
|
||||
recv_life_ct: int = -1
|
||||
if _g_new_storage is None: recv_life_ct = GenTypes.LIFE_FRAME
|
||||
# Diagnostic node: the first ctor arg (has a line number) so _call_method_on_ptr's
|
||||
# fatal_error can show the call line (this function has no cl param).
|
||||
diag_node_ct: ast.AST* = None
|
||||
@@ -168,7 +173,7 @@ novirtual class CallGenCtor(CallGenBase.CallGenBase):
|
||||
arg_vals[real_arg_count] = sizet(av)
|
||||
real_arg_count += 1
|
||||
|
||||
self.Gen.CallGenCall._call_method_on_ptr(pool, builder, mod, class_name, "__init__", storage_ptr, arg_vals, real_arg_count, trans, diag_node_ct, is_volatile, cargs)
|
||||
self.Gen.CallGenCall._call_method_on_ptr(pool, builder, mod, class_name, "__init__", storage_ptr, arg_vals, real_arg_count, trans, diag_node_ct, is_volatile, cargs, recv_life_ct)
|
||||
elif has_new_flag == 0:
|
||||
# No __init__ and no __new__: store args field by field
|
||||
# (with __new__, args were already consumed and must not be stored).
|
||||
@@ -548,6 +553,11 @@ novirtual class CallGenCtor(CallGenBase.CallGenBase):
|
||||
tmp: mlirlite.Value* = _g_new_storage
|
||||
if tmp is None: tmp = self.Gen.VarGen._alloca_at_entry(builder, struct_ty)
|
||||
if tmp is None: return mlirlite.ConstZero(pool, struct_ty)
|
||||
# 构造器同命裁剪用:被构造对象的生命期。
|
||||
# 裸 `T()`(没有 `new` 描述符提供存储)= 入口块 alloca → **FRAME**;
|
||||
# 存储来自 `new …`(_g_new_storage 非空)时来源/生命期由**上游**决定,这里不猜 → -1(不裁剪)。
|
||||
recv_life_ct: int = -1
|
||||
if _g_new_storage is None: recv_life_ct = GenTypes.LIFE_FRAME
|
||||
# Diagnostic node: the first ctor arg (has a line number) so _call_method_on_ptr's
|
||||
# fatal_error can show the call line (this function has no cl param).
|
||||
diag_node_ct: ast.AST* = None
|
||||
@@ -662,7 +672,7 @@ novirtual class CallGenCtor(CallGenBase.CallGenBase):
|
||||
init_arg_count += 1
|
||||
|
||||
# call __init__(storage_ptr, *args)
|
||||
self.Gen.CallGenCall._call_method_on_ptr(pool, builder, mod, class_name, "__init__", storage_ptr, init_arg_vals, init_arg_count, trans, diag_node_ct, is_volatile, cargs)
|
||||
self.Gen.CallGenCall._call_method_on_ptr(pool, builder, mod, class_name, "__init__", storage_ptr, init_arg_vals, init_arg_count, trans, diag_node_ct, is_volatile, cargs, recv_life_ct)
|
||||
|
||||
# return the pointer
|
||||
return storage_ptr
|
||||
|
||||
Reference in new issue
Block a user