Merge pull request #1483 from def-/fix-1449

Fix array address on nkHiddenAddr
This commit is contained in:
Andreas Rumpf 2014-08-15 21:32:09 +02:00
commit e9f623c07b

View file

@ -881,14 +881,15 @@ proc genArrayAddr(p: PProc, n: PNode, r: var TCompRes) =
a, b: TCompRes a, b: TCompRes
first: BiggestInt first: BiggestInt
r.typ = etyBaseIndex r.typ = etyBaseIndex
gen(p, n.sons[0], a) let m = if n.kind == nkHiddenAddr: n.sons[0] else: n
gen(p, n.sons[1], b) gen(p, m.sons[0], a)
gen(p, m.sons[1], b)
internalAssert a.typ != etyBaseIndex and b.typ != etyBaseIndex internalAssert a.typ != etyBaseIndex and b.typ != etyBaseIndex
r.address = a.res r.address = a.res
var typ = skipTypes(n.sons[0].typ, abstractPtrs) var typ = skipTypes(m.sons[0].typ, abstractPtrs)
if typ.kind in {tyArray, tyArrayConstr}: first = firstOrd(typ.sons[0]) if typ.kind in {tyArray, tyArrayConstr}: first = firstOrd(typ.sons[0])
else: first = 0 else: first = 0
if optBoundsCheck in p.options and not isConstExpr(n.sons[1]): if optBoundsCheck in p.options and not isConstExpr(m.sons[1]):
useMagic(p, "chckIndx") useMagic(p, "chckIndx")
r.res = ropef("chckIndx($1, $2, $3.length)-$2", r.res = ropef("chckIndx($1, $2, $3.length)-$2",
[b.res, toRope(first), a.res]) [b.res, toRope(first), a.res])