diff options
Diffstat (limited to 'tests/programs/bounds_ptr.zc')
| -rw-r--r-- | tests/programs/bounds_ptr.zc | 18 |
1 files changed, 18 insertions, 0 deletions
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; +} |
