- NewLifetimeTest(正向,9 用例自检 + 退出码判定):出口释放 / 循环内覆盖释放 / 别名只释放一次 / 嵌套函数登记区间隔离 / early return / void 裸 return / 仅分支里 new 时 free(NULL) / stack slife 不释放。 - NewLifetimeFreeTest(负向):对 slife 对象手动 stdlib.free → LifetimeError。 - SequentialRegressionTest 增 IR_EXPECT:编译成功后断言生成的 IR 出现 llvm.call @free(漏释放=纯泄漏,退出码看不出来);--escape/--only 纳入两个新项目,run_lifetime_negative_tests.py 同步。
29 lines
856 B
Plaintext
29 lines
856 B
Plaintext
from stdint import *
|
||
import w32.win32console
|
||
import t, c
|
||
from t import CInt, CExport
|
||
import stdlib
|
||
|
||
|
||
# =============================================================================
|
||
# 负向工程(**应当编译失败**,对照工程:NewLifetimeTest)
|
||
#
|
||
# §4.3 判据 5:`slife` 对象由编译器独占释放 —— 禁止手动 free。
|
||
# 理由:出口已经会自动 free 一次,再手动 free 就是 double-free。
|
||
# 期望报错:LifetimeError。
|
||
# =============================================================================
|
||
|
||
|
||
novirtual class Point:
|
||
x: int
|
||
y: int
|
||
|
||
|
||
def main() -> CInt | CExport:
|
||
w32.win32console.SetConsoleCP(65001)
|
||
w32.win32console.SetConsoleOutputCP(65001)
|
||
|
||
p: Point* = new heap slife Point(1, 2)
|
||
stdlib.free(p) # ← 必须被拒:slife 由编译器在函数出口释放
|
||
return 0
|