Skip to content

Commit

Permalink
fixes #23354; [backport] (#23685)
Browse files Browse the repository at this point in the history
  • Loading branch information
Araq authored Jun 7, 2024
1 parent 8f5ae28 commit 7039b8b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
3 changes: 3 additions & 0 deletions compiler/ccgutils.nim
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,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):
Expand Down
17 changes: 17 additions & 0 deletions tests/refc/tsinkbug.nim
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 7039b8b

Please sign in to comment.