From cd49bba7b3f350815cfefe8b353683288bb680de Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Thu, 20 Jun 2019 19:39:19 +0200 Subject: [PATCH] [bugfix] proper destruction for strings/seqs for --newruntime (cherry picked from commit 7e4748beeee3b7fb89801f6fe1e9693423e36f86) --- compiler/ccgexprs.nim | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim index 4eaa5a17d6..2d434748c3 100644 --- a/compiler/ccgexprs.nim +++ b/compiler/ccgexprs.nim @@ -2061,18 +2061,19 @@ proc genMove(p: BProc; n: PNode; d: var TLoc) = proc genDestroy(p: BProc; n: PNode) = 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 of tyString: var a: TLoc - initLocExpr(p, n[1].skipAddr, a) - linefmt(p, cpsStmts, "if ($1.len && $1.p->allocator) {$n" & + initLocExpr(p, arg, a) + 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", [rdLoc(a)]) of tySequence: var a: TLoc - initLocExpr(p, n[1].skipAddr, a) - linefmt(p, cpsStmts, "if ($1.len && $1.p->allocator) {$n" & + initLocExpr(p, arg, a) + 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", [rdLoc(a), getTypeDesc(p.module, t.lastSon)]) else: discard "nothing to do"