From 36f8cccda47c3bc6a8e5cc2bd6b914181eefbf73 Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Fri, 7 Jun 2024 09:01:30 +0200 Subject: [PATCH] fixes #23354; [backport] (#23685) (cherry picked from commit 7039b8b5bc5c62cdd608a769e0ea556e23973cc5) --- compiler/ccgutils.nim | 3 +++ tests/refc/tsinkbug.nim | 17 +++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 tests/refc/tsinkbug.nim diff --git a/compiler/ccgutils.nim b/compiler/ccgutils.nim index ebef00e101..f83014afd1 100644 --- a/compiler/ccgutils.nim +++ b/compiler/ccgutils.nim @@ -134,6 +134,9 @@ proc ccgIntroducedPtr*(conf: ConfigRef; s: PSym, retType: PType): bool = if s.typ.sym != nil and sfForward in s.typ.sym.flags: # forwarded objects are *always* passed by pointers for consistency! result = true + elif s.typ.kind == tySink and conf.selectedGC notin {gcArc, gcAtomicArc, gcOrc, gcHooks}: + # bug #23354: + result = false elif (optByRef in s.options) or (getSize(conf, pt) > conf.target.floatSize * 3): result = true # requested anyway elif (tfFinal in pt.flags) and (pt[0] == nil): diff --git a/tests/refc/tsinkbug.nim b/tests/refc/tsinkbug.nim new file mode 100644 index 0000000000..2cd762f405 --- /dev/null +++ b/tests/refc/tsinkbug.nim @@ -0,0 +1,17 @@ +discard """ + matrix: "--gc:refc; --gc:arc" + output: ''' +Value is: 42 +Value is: 42''' +""" + +type AnObject* = object of RootObj + value*: int + +proc mutate(a: sink AnObject) = + a.value = 1 + +var obj = AnObject(value: 42) +echo "Value is: ", obj.value +mutate(obj) +echo "Value is: ", obj.value