Files
Viper_RegressionTesting/NewLifetimeFreeTest/App/main.vp
T
TermiNexus 7451adf523 test(lifetime): 新增 NewLifetimeTest/NewLifetimeFreeTest 与 IR 断言,escape 跑法纳入新项目
- 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 同步。
2026-10-08 20:04:12 +08:00

29 lines
856 B
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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