[bugfix] proper destruction for strings/seqs for --newruntime

This commit is contained in:
Andreas Rumpf 2019-06-20 19:39:19 +02:00
commit 7e4748beee

View file

@ -2061,18 +2061,19 @@ proc genMove(p: BProc; n: PNode; d: var TLoc) =
proc genDestroy(p: BProc; n: PNode) = proc genDestroy(p: BProc; n: PNode) =
if optNimV2 in p.config.globalOptions: if optNimV2 in p.config.globalOptions:
let t = n[1].typ.skipTypes(abstractInst) let arg = n[1].skipAddr
let t = arg.typ.skipTypes(abstractInst)
case t.kind case t.kind
of tyString: of tyString:
var a: TLoc var a: TLoc
initLocExpr(p, n[1].skipAddr, a) initLocExpr(p, arg, a)
linefmt(p, cpsStmts, "if ($1.len && $1.p->allocator) {$n" & linefmt(p, cpsStmts, "if ($1.p && $1.p->allocator) {$n" &
" $1.p->allocator->dealloc($1.p->allocator, $1.p, $1.p->cap + 1 + sizeof(NI) + sizeof(void*)); }$n", " $1.p->allocator->dealloc($1.p->allocator, $1.p, $1.p->cap + 1 + sizeof(NI) + sizeof(void*)); }$n",
[rdLoc(a)]) [rdLoc(a)])
of tySequence: of tySequence:
var a: TLoc var a: TLoc
initLocExpr(p, n[1].skipAddr, a) initLocExpr(p, arg, a)
linefmt(p, cpsStmts, "if ($1.len && $1.p->allocator) {$n" & linefmt(p, cpsStmts, "if ($1.p && $1.p->allocator) {$n" &
" $1.p->allocator->dealloc($1.p->allocator, $1.p, ($1.p->cap * sizeof($2)) + sizeof(NI) + sizeof(void*)); }$n", " $1.p->allocator->dealloc($1.p->allocator, $1.p, ($1.p->cap * sizeof($2)) + sizeof(NI) + sizeof(void*)); }$n",
[rdLoc(a), getTypeDesc(p.module, t.lastSon)]) [rdLoc(a), getTypeDesc(p.module, t.lastSon)])
else: discard "nothing to do" else: discard "nothing to do"