test(lifetime): 补 P3 注解形态 + P2 方法级/取地址的自动工程
- 新增 NewLifetimeAnnFieldEscapeTest:h.p: int* = &local → LifetimeError(P3 注解形态) - 新增 NewLifetimeWillFreeMethodTest:r.Release(p) 后再用 p → LifetimeError(方法级标注,形参位含 self 偏移) - 新增 NewLifetimeWillFreeAddrTest:stdlib.free(p) 后 &p → LifetimeError(取地址路径) - NewLifetimeTest.CaseAnnFieldStore:p.x: int = 42 必须真的写进字段(正向) - 注册进 SequentialRegressionTest / regression_test / run_lifetime_negative_tests + README
This commit is contained in:
1 parent
64b0cc84f6
commit
5fa5a9f37c
11 files changed
+201
-5
No files matched your search
@@ -0,0 +1,32 @@
|
||||
from stdint import *
|
||||
import stdlib
|
||||
|
||||
|
||||
# =============================================================================
|
||||
# 负向工程(**应当编译失败**)
|
||||
#
|
||||
# P2 willFree —— **方法级**标注路径。`includes/stdlib.vp` 的 `free` 上那处 `@life(willFree(p))`
|
||||
# 走的是**模块级函数调用**;本工程覆盖另一条独立链路:
|
||||
# · 注册:StructGenMixin._RegisterClassMethods → _RegisterFuncWillFree(键 "Class.method");
|
||||
# · 查询:CallGenCall._translate_method_call 的 wf_mask_mc = get_param_willfree_method(...);
|
||||
# · 形参位映射:实参链含 self(bit 0),故用户第 ai 个实参对应形参位 (ai+1)。
|
||||
#
|
||||
# 本工程:`r.Release(p)` 之后 p 即失效,再 `free(p)` 必须被拒(二次释放)。
|
||||
# 期望报错:LifetimeError。
|
||||
# =============================================================================
|
||||
|
||||
|
||||
novirtual class Resource:
|
||||
id: int
|
||||
|
||||
@life(willFree(p))
|
||||
def Release(self, p: rawptr) -> None:
|
||||
stdlib.free(p)
|
||||
|
||||
|
||||
export def main() -> int:
|
||||
r: Resource* = new heap hlife Resource(1)
|
||||
p: rawptr = stdlib.malloc(8)
|
||||
r.Release(p) # ← 本调用后 p 失效(被调者带 @life(willFree(p)))
|
||||
stdlib.free(p) # ← 必须被拒:p 已失效(二次释放)
|
||||
return 0
|
||||
@@ -0,0 +1,29 @@
|
||||
{
|
||||
"$schema": "https://raw.githubusercontent.com/TermiNexus/TransPyC/main/schemas/project-schema.json",
|
||||
"name": "NewLifetimeWillFreeMethodTest",
|
||||
"version": "1.0.0",
|
||||
"source_dir": "./App",
|
||||
"build_dir": "./.tpv_build",
|
||||
"compiler": {
|
||||
"cmd": "llc",
|
||||
"flags": ["-filetype=obj", "-relocation-model=pic"]
|
||||
},
|
||||
"linker": {
|
||||
"cmd": "clang++",
|
||||
"flags": ["-lmsvcrt", "-lucrt", "-lpthread", "-lmingwex", "-lkernel32"],
|
||||
"output": "NewLifetimeWillFreeMethodTest.exe"
|
||||
},
|
||||
"includes": [
|
||||
"../../includes"
|
||||
],
|
||||
"target": {
|
||||
"triple": "x86_64-pc-windows-gnu",
|
||||
"datalayout": "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
|
||||
},
|
||||
"options": {
|
||||
"slice_level": 3,
|
||||
"sha1_slice_level": 1,
|
||||
"target": "llvm",
|
||||
"strict_mode": true
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user