diff options
| author | 2026-10-14 16:08:34 +0330 | |
|---|---|---|
| committer | 2026-10-14 16:08:34 +0330 | |
| commit | 76a4db8ef506e4fb2c3eb530a3d95904a42ca0cb (patch) | |
| tree | 6cf50f1bd3d5e44d8d0306e7547d072c9822fa27 /src/compiler/expr.zc | |
| parent | bounds checking: port agent/bounds-checking onto main 0879d0a; unbounded main... (diff) | |
bounds checking: constant loop bound proof works, plain-op fixed-array check, docs (readme, spec 4.15 and friends, server, vscode), conformance and test.sh fixes, todo
Diffstat (limited to 'src/compiler/expr.zc')
| -rw-r--r-- | src/compiler/expr.zc | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/src/compiler/expr.zc b/src/compiler/expr.zc index c76b74c..1536744 100644 --- a/src/compiler/expr.zc +++ b/src/compiler/expr.zc @@ -1322,12 +1322,14 @@ int range_jz(int ix, int src, int fld) { return 0; } // the inline check of a fixed array T[n]: the index is on top of the stack and -// stays there. one "outside" enhancement against the constant length and a -// branch to the oob report, the same shape as range_jz. +// stays there. i is outside 0..n-1 exactly when i | (n - 1 - i) is negative: +// one subtract, one or and one compare, then a branch to the oob report. no +// enhancement: the x86-64 jit calls one rather than inlining it. int fixed_chk(int n) { - int k = lookup(s_outside), j; - if (k < 0 || skind[k] != K_ENH) return 0; - lit(0); op(O_PICK); lit(n); op(XOP0 + sval[k]); + int j; + lit(0); op(O_PICK); lit(n - 1); op(O_SWAP); op(O_SUB); + lit(1); op(O_PICK); op(17); + lit(0); op(O_LT); j = hole(); op(O_JZ); lit(n); callname(s_oob); setlit(j, here); @@ -1753,7 +1755,7 @@ int bin(int minp) { if (top) { ft_nops++; if (ft_nops > 1) ft_iv = -1; - else if (bname[b] == s_lt && blen[b] > 0 && il >= 0 && ft_ir >= 0 && !lf && !rf && !ls && !rs) { ft_iv = il; ft_bd = ft_ir; } + else if (bname[b] == s_lt && blen[b] > 0 && il >= 0 && (ft_ir >= 0 || ft_ck >= 0) && !lf && !rf && !ls && !rs) { ft_iv = il; ft_bd = ft_ir; } } lv = 0; lvk = LV_NONE; c = C_PLAIN; xzero = 0; xconst = 0; xlenloc = -1; xstamp = 0; xaf = 0; xvk = 0; effect_value = 0; if (isptr(xty) || xty == tword) effect_value = left_mask | right_mask; |
