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_hoist.zc | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 tests/programs/bounds_hoist.zc (limited to 'tests/programs/bounds_hoist.zc') diff --git a/tests/programs/bounds_hoist.zc b/tests/programs/bounds_hoist.zc new file mode 100644 index 0000000..d7f5e7f --- /dev/null +++ b/tests/programs/bounds_hoist.zc @@ -0,0 +1,20 @@ +namespace; +include rt; + +// a loop for (i = 0; i < n; i++) with an int bound n the body leaves alone: +// the check of t[i] against t's length is worked out once at the loop entry +// (0 <= i and n <= length) and runs on each access only when that failed. so +// a loop that stays inside skips it, and one that runs past the end still +// faults at the same access, after the same side effects (the puts before it). +int[8] t; +int sweep(int n) { int i, s = 0; for (i = 0; i < n; i++) { t[i] = i; s = s + t[i]; } return s; } +int from(int lo, int n) { int i, s = 0; for (i = lo; i < n; i++) s = s + t[i]; return s; } +int main() { + rt.put_n(sweep(8)); rt.put_c(10); + rt.put_n(sweep(3)); rt.put_c(10); + rt.put_n(from(2, 8)); rt.put_c(10); + int i, n = 10; + for (i = 0; i < n; i++) { rt.put_n(i); rt.put_c(32); t[i] = i; } + rt.put_s("not reached\n"); + return 0; +} -- cgit v1.2.3