'add' on a nil sequence doesn't produce a crash anymore

This commit is contained in:
Andreas Rumpf 2018-04-27 09:57:14 +02:00
commit ef1b547f35
2 changed files with 16 additions and 4 deletions

View file

@ -1086,17 +1086,17 @@ 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) #incrSeqV2(&($1)->Sup, sizeof($3));$n"
"$1 = ($2) #incrSeqV3(&($1)->Sup, $3);$n"
else:
"$1 = ($2) #incrSeqV2($1, sizeof($3));$n"
"$1 = ($2) #incrSeqV3($1, $3);$n"
var a, b, dest, tmpL: TLoc
initLocExpr(p, e.sons[1], a)
initLocExpr(p, e.sons[2], b)
let bt = skipTypes(e.sons[2].typ, {tyVar})
let seqType = skipTypes(e.sons[1].typ, {tyVar})
lineCg(p, cpsStmts, seqAppendPattern, [
rdLoc(a),
getTypeDesc(p.module, e.sons[1].typ),
getTypeDesc(p.module, bt)])
genTypeInfo(p.module, seqType, e.info)])
#if bt != b.t:
# echo "YES ", e.info, " new: ", typeToString(bt), " old: ", typeToString(b.t)
initLoc(dest, locExpr, e.sons[2], OnHeap)