diff options
| author | 2026-10-14 16:24:55 +0330 | |
|---|---|---|
| committer | 2026-10-14 16:24:55 +0330 | |
| commit | 886fa9c0b7ad3c0316e85de1b2c87c54a3681b12 (patch) | |
| tree | c586a0d5428cbdb019b80f5a92a8ffd80c0d962d /tests/programs/bounds_fixed.zc | |
| parent | rt.zdiv: INT_MIN / -1 is INT_MIN and % is 0 in software division too, so zc0 ... (diff) | |
| parent | merge bounds checking (diff) | |
Merge branch 'main' into work/spec
Diffstat (limited to 'tests/programs/bounds_fixed.zc')
| -rw-r--r-- | tests/programs/bounds_fixed.zc | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/tests/programs/bounds_fixed.zc b/tests/programs/bounds_fixed.zc new file mode 100644 index 0000000..0b3f476 --- /dev/null +++ b/tests/programs/bounds_fixed.zc @@ -0,0 +1,17 @@ +namespace; +include rt; + +// a fixed array T[n] with a variable index is checked against n. a loop whose +// test is the constant n proves the index and drops the check; a constant +// index is checked when it is compiled. +int main() { + int[6] t; int i, s = 0, k = 6; + for (i = 0; i < 6; i++) t[i] = i * i; + for (i = 0; i < 6; i++) s = s + t[i]; + rt.put_n(s); rt.put_c(10); + i = 2; rt.put_n(t[i] + t[5]); rt.put_c(10); + i = 0; + while (i <= k) { s = t[i]; i++; } + rt.put_s("not reached\n"); + return 0; +} |
