fix(lifetime): 值类型局部变量在同型聚合目标位置按值拷贝(LIFE_VALUE) - 修 return col 被误判 stack address escapes
This commit is contained in:
1 parent
217f5f021d
commit
6b86f846ca
1 file changed
+10
@@ -1041,6 +1041,16 @@ novirtual class AssignGenMixin:
|
|||||||
# 本帧局部数组名:退让到指针目标交出栈地址;同型聚合目标是值拷贝
|
# 本帧局部数组名:退让到指针目标交出栈地址;同型聚合目标是值拷贝
|
||||||
if target_ty is not None and self.Gen.ExprGenBase.is_ptr_type(target_ty) != 0: return GenTypes.LIFE_FRAME
|
if target_ty is not None and self.Gen.ExprGenBase.is_ptr_type(target_ty) != 0: return GenTypes.LIFE_FRAME
|
||||||
return GenTypes.LIFE_VALUE
|
return GenTypes.LIFE_VALUE
|
||||||
|
# 值类型(聚合)局部变量的存储是入口块 alloca(符号表登记的是 alloca 指针,见
|
||||||
|
# VarGenMixin.lookup_var),但**目标位置是同型聚合值**时语义是值拷贝:交出的是整块
|
||||||
|
# 拷贝,与源帧无关 ⇒ LIFE_VALUE。与下方 Call 分支的裸构造 `T(...)` 同口径。
|
||||||
|
# 此前只对「裸数组名(inner 是 Array)」给了这条口径,于是 `col: V3 = V3(...)` 后
|
||||||
|
# `return col` 落到 get_var_life 读回本帧 LIFE_FRAME,被 check_return_frame_decl 误拦
|
||||||
|
# (LifetimeError: stack address escapes)。
|
||||||
|
if (inner is not None and target_ty is not None
|
||||||
|
and self.Gen.ExprGenBase.is_ptr_type(target_ty) == 0
|
||||||
|
and self._stg_ty_equal(trans.Pool, inner, target_ty) != 0):
|
||||||
|
return GenTypes.LIFE_VALUE
|
||||||
# 指针/标量变量:读登记的生命期(默认 UNKNOWN)
|
# 指针/标量变量:读登记的生命期(默认 UNKNOWN)
|
||||||
return self.Gen.VarGen.get_var_life(trans.SymTab, nm.id)
|
return self.Gen.VarGen.get_var_life(trans.SymTab, nm.id)
|
||||||
if k == ast.ASTKind.UnaryOp:
|
if k == ast.ASTKind.UnaryOp:
|
||||||
|
|||||||
Reference in new issue
Block a user