summary refs log tree commit diff stats
path: root/compiler/ccgexprs.nim
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2019-06-20 19:39:19 +0200
committerAndreas Rumpf <rumpf_a@web.de>2019-06-20 19:39:19 +0200
commit7e4748beeee3b7fb89801f6fe1e9693423e36f86 (patch)
treec16fd818bee7fb656c308d351e67fd69b3f916c7 /compiler/ccgexprs.nim
parentbc9fb4885b8a50cdb8e9a47ec1092e1879db9f9f (diff)
downloadNim-7e4748beeee3b7fb89801f6fe1e9693423e36f86.tar.gz
[bugfix] proper destruction for strings/seqs for --newruntime
Diffstat (limited to 'compiler/ccgexprs.nim')
-rw-r--r--compiler/ccgexprs.nim11
1 files changed, 6 insertions, 5 deletions
diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim
index 4eaa5a17d..2d434748c 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"