From 459b7661aaa0d65d01be064bd4b9976c4f045a5c Mon Sep 17 00:00:00 2001 From: zinc Date: Wed, 14 Oct 2026 18:22:04 +0330 Subject: bounds: body scan, loop-entry hoisting, pointer proofs from requested size, --explain-checks v1 (non-o3 code) --- tests/programs/bounds_ptr.zc | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 tests/programs/bounds_ptr.zc (limited to 'tests/programs/bounds_ptr.zc') diff --git a/tests/programs/bounds_ptr.zc b/tests/programs/bounds_ptr.zc new file mode 100644 index 0000000..3190b03 --- /dev/null +++ b/tests/programs/bounds_ptr.zc @@ -0,0 +1,18 @@ +namespace; +include rt; + +// a pointer set from rt.new(n) with a constant n: a loop test i < n drops the +// check, a variable bound hoists it to the loop entry, and a body that calls +// something keeps it (the call might free the block). all three agree. +int main() { + int* p = rt.new(16); int i, s = 0, n = 16; + for (i = 0; i < 16; i++) p[i] = i; + for (i = 0; i < n; i++) s = s + p[i]; + rt.put_n(s); rt.put_c(10); + for (i = 0; i < n; i++) { s = s + p[i]; rt.put_s(""); } + rt.put_n(s); rt.put_c(10); + n = 1000; + for (i = 0; i < n; i++) s = s + p[i]; + rt.put_s("not reached\n"); + return 0; +} -- cgit v1.2.3