summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2023-07-06 15:15:50 +0200
committerGitHub <noreply@github.com>2023-07-06 15:15:50 +0200
commita15db5d60b39a24886c692bc9a4e2cb3d5d33ef2 (patch)
tree687d461e6065cddb0a3c705c938d8455cab45077
parentdfa0d2569e772d6fc4568796db03f65dc2e94771 (diff)
downloadNim-a15db5d60b39a24886c692bc9a4e2cb3d5d33ef2.tar.gz
fixes #22175 (#22229)
-rw-r--r--compiler/ccgexprs.nim7
-rw-r--r--tests/arc/t17812.nim12
2 files changed, 17 insertions, 2 deletions
diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim
index c585290cd..00781a31d 100644
--- a/compiler/ccgexprs.nim
+++ b/compiler/ccgexprs.nim
@@ -2357,8 +2357,11 @@ proc genMove(p: BProc; n: PNode; d: var TLoc) =
     linefmt(p, cpsStmts, "}$n$1.len = $2.len; $1.p = $2.p;$n", [rdLoc(a), rdLoc(src)])
   else:
     if d.k == locNone: getTemp(p, n.typ, d)
-    genAssignment(p, d, a, {})
-    if p.config.selectedGC notin {gcArc, gcAtomicArc, gcOrc}:
+    if p.config.selectedGC in {gcArc, gcAtomicArc, gcOrc}:
+      genAssignment(p, d, a, {})
+    else:
+      let flags = if not canMove(p, n[1], d): {needToCopy} else: {}
+      genAssignment(p, d, a, flags)
       resetLoc(p, a)
 
 proc genDestroy(p: BProc; n: PNode) =
diff --git a/tests/arc/t17812.nim b/tests/arc/t17812.nim
index bcd5f3a93..dd8ac89b0 100644
--- a/tests/arc/t17812.nim
+++ b/tests/arc/t17812.nim
@@ -27,3 +27,15 @@ block: # bug #17812
     proc `$`(o: MyObj): string = o.repr
 
     doAssert ($MyObj()).len > 0
+
+# bug #22175
+
+type Xxx = object
+  value: string
+
+proc complete(xxx: ref Xxx, v: sink string) =
+  xxx.value = move(v)
+
+let yyy = (ref Xxx)()
+
+yyy.complete("test")