interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / tests / compiler / progs / handles_stale.osc

43 lines · 1094 bytes Raw Blame History
1// entry: stale dfree aba
2// OSC-3 item 2: a free the checker cannot decide (behind a branch) leaves the
3// handle and its copies checked at run time: a use or free whose generation
4// no longer matches the slot traps STALE, also after the slot was reused.
5// expect-run: stale 0 -> 7
6// expect-run: stale 1 -> trap=STALE
7// expect-run: dfree 0 -> 1
8// expect-run: dfree 1 -> trap=STALE
9// expect-run: aba 0 -> 10
10// expect-run: aba 1 -> trap=STALE
11fn stale(k: u8) -> i64 {
12 let mut s: i64 = 0;
13 pool p: [i64; 2] {
14 let h: handle p = p.alloc(7);
15 let c: handle p = h;
16 if k > 0 { p.free(h); }
17 s = p[c];
18 }
19 return s;
20}
21
22fn dfree(k: u8) -> i64 {
23 pool p: [i64; 1] {
24 let h: handle p = p.alloc(5);
25 if k == 1 { p.free(h); }
26 p.free(h);
27 }
28 return 1;
29}
30
31fn aba(k: u8) -> i64 {
32 let mut s: i64 = 0;
33 pool p: [i64; 1] {
34 let mut h: handle p = p.alloc(5);
35 let old: handle p = h;
36 if k > 0 {
37 p.free(h);
38 h = p.alloc(9);
39 }
40 s = p[h] + p[old];
41 }
42 return s;
43}