fixes #1832
This commit is contained in:
parent
18823a315e
commit
4932415742
3 changed files with 28 additions and 3 deletions
|
|
@ -1052,9 +1052,9 @@ proc genSeqElemAppend(p: BProc, e: PNode, d: var TLoc) =
|
|||
# seq = (typeof seq) incrSeq(&seq->Sup, sizeof(x));
|
||||
# seq->data[seq->len-1] = x;
|
||||
let seqAppendPattern = if not p.module.compileToCpp:
|
||||
"$1 = ($2) #incrSeq(&($1)->Sup, sizeof($3));$n"
|
||||
"$1 = ($2) #incrSeqV2(&($1)->Sup, sizeof($3));$n"
|
||||
else:
|
||||
"$1 = ($2) #incrSeq($1, sizeof($3));$n"
|
||||
"$1 = ($2) #incrSeqV2($1, sizeof($3));$n"
|
||||
var a, b, dest: TLoc
|
||||
initLocExpr(p, e.sons[1], a)
|
||||
initLocExpr(p, e.sons[2], b)
|
||||
|
|
@ -1064,8 +1064,9 @@ proc genSeqElemAppend(p: BProc, e: PNode, d: var TLoc) =
|
|||
getTypeDesc(p.module, skipTypes(e.sons[2].typ, abstractVar))])
|
||||
keepAlive(p, a)
|
||||
initLoc(dest, locExpr, b.t, OnHeap)
|
||||
dest.r = rfmt(nil, "$1->data[$1->$2-1]", rdLoc(a), lenField(p))
|
||||
dest.r = rfmt(nil, "$1->data[$1->$2]", rdLoc(a), lenField(p))
|
||||
genAssignment(p, dest, b, {needToCopy, afDestIsNil})
|
||||
lineCg(p, cpsStmts, "++$1->$2;$n", rdLoc(a), lenField(p))
|
||||
gcUsage(e)
|
||||
|
||||
proc genReset(p: BProc, n: PNode) =
|
||||
|
|
|
|||
|
|
@ -210,6 +210,14 @@ proc incrSeq(seq: PGenericSeq, elemSize: int): PGenericSeq {.compilerProc.} =
|
|||
GenericSeqSize))
|
||||
inc(result.len)
|
||||
|
||||
proc incrSeqV2(seq: PGenericSeq, elemSize: int): PGenericSeq {.compilerProc.} =
|
||||
# incrSeq version 2
|
||||
result = seq
|
||||
if result.len >= result.space:
|
||||
result.reserved = resize(result.space)
|
||||
result = cast[PGenericSeq](growObj(result, elemSize * result.reserved +
|
||||
GenericSeqSize))
|
||||
|
||||
proc setLengthSeq(seq: PGenericSeq, elemSize, newLen: int): PGenericSeq {.
|
||||
compilerRtl.} =
|
||||
result = seq
|
||||
|
|
|
|||
16
tests/ccgbugs/taddhigh.nim
Normal file
16
tests/ccgbugs/taddhigh.nim
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
discard """
|
||||
output: '''@[5, 5, 5]'''
|
||||
"""
|
||||
|
||||
# bug #1832
|
||||
|
||||
var s = @[5]
|
||||
|
||||
# Works fine:
|
||||
let x = s[s.high]
|
||||
s.add x
|
||||
|
||||
# Causes the 0 to appear:
|
||||
s.add s[s.high]
|
||||
|
||||
echo s # @[5, 5, 0]
|
||||
Loading…
Add table
Add a link
Reference in a new issue