aboutsummaryrefslogtreecommitdiff
path: root/tests/conformance/6-ownership/drop_reused_address.zc
diff options
context:
space:
mode:
authorGravatar zinc <zinc@downsta.ir> 2026-10-15 00:53:25 +0330
committerGravatar zinc <zinc@downsta.ir> 2026-10-15 00:53:25 +0330
commit0e333abab5d684be37043196b4c006b71bdf850e (patch)
treed7e6664befd82268d2681c817542b3592bab379d /tests/conformance/6-ownership/drop_reused_address.zc
parentbench: sieve.zc and trees.zc take namespace and include rt, so run.py's check... (diff)
parenttodo: destructors item closed with what landed; what is left (reassignment fr... (diff)
merge work/dtor: destructors (drop on any heap value, heap(), struct drop, collector drops once with resurrection, freed blocks forget their drop)
Diffstat (limited to 'tests/conformance/6-ownership/drop_reused_address.zc')
-rw-r--r--tests/conformance/6-ownership/drop_reused_address.zc22
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/conformance/6-ownership/drop_reused_address.zc b/tests/conformance/6-ownership/drop_reused_address.zc
new file mode 100644
index 0000000..97ef21d
--- /dev/null
+++ b/tests/conformance/6-ownership/drop_reused_address.zc
@@ -0,0 +1,22 @@
+// expect: drop 1 same 1 1 0/
+// destructors 9: a freed block's drop and its bits are cleared, so a block reused at the same address runs no old drop
+include rt;
+int n, first;
+int addr(int* p) { return p as int; }
+int clean(int* p) { unbounded { return (p[-4] & (rt.F_HASDROP | rt.F_DROPPED)) == 0; } }
+// the drop is set in a helper, so main has no closure and its locals take no cells from the heap
+int* .u armed() { int* p = rt.new(int); p.drop = fn() { n++; rt.put_s("drop "); }; return p; }
+fn main() {
+ { int* p = armed(); *p = 1; first = addr(p); }
+ rt.put_n(n); rt.put_c(32);
+ {
+ int* q = rt.new(int); *q = 2;
+ if (addr(q) == first) rt.put_s("same "); else rt.put_s("moved ");
+ rt.put_n(clean(q)); rt.put_c(32);
+ }
+ rt.put_n(n); rt.put_c(32);
+ rt.put_n(rt.dcount);
+ rt.put_c(10);
+ return 0;
+}
+// zc0: skip