Merge pull request #9881 from timotheecour/pr_ref_9880
refs #9880 show index and bound in lots of `index out of bounds` errors
This commit is contained in:
commit
bb1ce398af
9 changed files with 64 additions and 23 deletions
|
|
@ -866,15 +866,15 @@ proc genArrayElem(p: BProc, n, x, y: PNode, d: var TLoc) =
|
|||
# semantic pass has already checked for const index expressions
|
||||
if firstOrd(p.config, ty) == 0:
|
||||
if (firstOrd(p.config, b.t) < firstOrd(p.config, ty)) or (lastOrd(p.config, b.t) > lastOrd(p.config, ty)):
|
||||
linefmt(p, cpsStmts, "if ((NU)($1) > (NU)($2)) #raiseIndexError();$n",
|
||||
linefmt(p, cpsStmts, "if ((NU)($1) > (NU)($2)) #raiseIndexError2($1, $2);$n",
|
||||
rdCharLoc(b), intLiteral(lastOrd(p.config, ty)))
|
||||
else:
|
||||
linefmt(p, cpsStmts, "if ($1 < $2 || $1 > $3) #raiseIndexError();$n",
|
||||
linefmt(p, cpsStmts, "if ($1 < $2 || $1 > $3) #raiseIndexError3($1, $2, $3);$n",
|
||||
rdCharLoc(b), first, intLiteral(lastOrd(p.config, ty)))
|
||||
else:
|
||||
let idx = getOrdValue(y)
|
||||
if idx < firstOrd(p.config, ty) or idx > lastOrd(p.config, ty):
|
||||
localError(p.config, x.info, "index out of bounds")
|
||||
localError(p.config, x.info, formatErrorIndexBound(idx, firstOrd(p.config, ty), lastOrd(p.config, ty)))
|
||||
d.inheritLocation(a)
|
||||
putIntoDest(p, d, n,
|
||||
ropecg(p.module, "$1[($2)- $3]", rdLoc(a), rdCharLoc(b), first), a.storage)
|
||||
|
|
@ -913,7 +913,7 @@ proc genOpenArrayElem(p: BProc, n, x, y: PNode, d: var TLoc) =
|
|||
initLocExpr(p, x, a)
|
||||
initLocExpr(p, y, b) # emit range check:
|
||||
if optBoundsCheck in p.options:
|
||||
linefmt(p, cpsStmts, "if ((NU)($1) >= (NU)($2Len_0)) #raiseIndexError();$n",
|
||||
linefmt(p, cpsStmts, "if ((NU)($1) >= (NU)($2Len_0)) #raiseIndexError2($1,$2Len_0-1);$n",
|
||||
rdLoc(b), rdLoc(a)) # BUGFIX: ``>=`` and not ``>``!
|
||||
inheritLocation(d, a)
|
||||
putIntoDest(p, d, n,
|
||||
|
|
@ -929,11 +929,11 @@ proc genSeqElem(p: BProc, n, x, y: PNode, d: var TLoc) =
|
|||
if optBoundsCheck in p.options:
|
||||
if ty.kind == tyString and (not defined(nimNoZeroTerminator) or optLaxStrings in p.options):
|
||||
linefmt(p, cpsStmts,
|
||||
"if ((NU)($1) > (NU)$2) #raiseIndexError();$n",
|
||||
"if ((NU)($1) > (NU)$2) #raiseIndexError2($1,$2);$n",
|
||||
rdLoc(b), lenExpr(p, a))
|
||||
else:
|
||||
linefmt(p, cpsStmts,
|
||||
"if ((NU)($1) >= (NU)$2) #raiseIndexError();$n",
|
||||
"if ((NU)($1) >= (NU)$2) #raiseIndexError2($1,$2-1);$n",
|
||||
rdLoc(b), lenExpr(p, a))
|
||||
if d.k == locNone: d.storage = OnHeap
|
||||
if skipTypes(a.t, abstractVar).kind in {tyRef, tyPtr}:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue