summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2015-07-22 01:21:42 +0200
committerAraq <rumpf_a@web.de>2015-07-22 01:21:42 +0200
commit862ee8d1d3f76dbbae0866f9048292a74fc07b71 (patch)
tree8733fbc8558d45e25d1ac6dd67538e593276acf9
parentf192d5aab3cb42bde437ca6aa7819272a55402d3 (diff)
downloadNim-862ee8d1d3f76dbbae0866f9048292a74fc07b71.tar.gz
fixes #2963
-rw-r--r--compiler/ccgexprs.nim4
-rw-r--r--compiler/ccgstmts.nim5
-rw-r--r--tests/ccgbugs/tmissingderef.nim13
3 files changed, 18 insertions, 4 deletions
diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim
index 493749848..2f4a1e039 100644
--- a/compiler/ccgexprs.nim
+++ b/compiler/ccgexprs.nim
@@ -347,8 +347,8 @@ proc genAssignment(p: BProc, dest, src: TLoc, flags: TAssignmentFlags) =
     else:
       useStringh(p.module)
       linefmt(p, cpsStmts,
-           "memcpy((void*)$1, (NIM_CONST void*)$2, sizeof($1));$n",
-           rdLoc(dest), rdLoc(src))
+           "memcpy((void*)$1, (NIM_CONST void*)$2, sizeof($3));$n",
+           rdLoc(dest), rdLoc(src), getTypeDesc(p.module, ty))
   of tyOpenArray, tyVarargs:
     # open arrays are always on the stack - really? What if a sequence is
     # passed to an open array?
diff --git a/compiler/ccgstmts.nim b/compiler/ccgstmts.nim
index 5129c8023..f12a24fa2 100644
--- a/compiler/ccgstmts.nim
+++ b/compiler/ccgstmts.nim
@@ -1101,7 +1101,10 @@ proc genAsgn(p: BProc, e: PNode, fastAsgn: bool) =
     genGotoVar(p, e.sons[1])
   elif not fieldDiscriminantCheckNeeded(p, e):
     var a: TLoc
-    initLocExpr(p, e.sons[0], a)
+    if e[0].kind in {nkDerefExpr, nkHiddenDeref}:
+      genDeref(p, e[0], a, enforceDeref=true)
+    else:
+      initLocExpr(p, e.sons[0], a)
     if fastAsgn: incl(a.flags, lfNoDeepCopy)
     assert(a.t != nil)
     loadInto(p, e.sons[0], e.sons[1], a)
diff --git a/tests/ccgbugs/tmissingderef.nim b/tests/ccgbugs/tmissingderef.nim
index edff1dd4e..26418800a 100644
--- a/tests/ccgbugs/tmissingderef.nim
+++ b/tests/ccgbugs/tmissingderef.nim
@@ -1,5 +1,7 @@
 discard """
-  output: '''255
+  output: '''[10, 0, 0, 0, 0, 0, 0, 0]
+
+255
 1 1
 0.5'''
 """
@@ -27,4 +29,13 @@ proc mainowar =
   var b = p[]
   echo b[0]
 
+
+# bug 2963
+var
+  a = [8, 7, 3, 10, 0, 0, 0, 1]
+  b = [10, 0, 0, 0, 0, 0, 0, 0]
+  ap = addr a
+ap[] = b
+echo repr(a)
+
 mainowar()