Skip to content

Commit a77d1cc

Browse files
authored
fixes #24844; Invalid C codegen refc with generic types containing gc memory (#25160)
fixes #24844 it may not be used in other places except in `genTraverseProc`, we have to generate a `typedesc` for this case, not a weak `typedec`
1 parent ff9cae8 commit a77d1cc

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

compiler/ccgtypes.nim

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2001,6 +2001,9 @@ proc genTypeInfoV1(m: BModule; t: PType; info: TLineInfo): Rope =
20012001
of tyRef:
20022002
genTypeInfoAux(m, t, t, result, info)
20032003
if m.config.selectedGC in {gcMarkAndSweep, gcRefc, gcGo}:
2004+
# it may not be used in other places except in `genTraverseProc`,
2005+
# we have to generate a typedesc for this case, not a weak one
2006+
discard getTypeDesc(m, origType.last)
20042007
let markerProc = genTraverseProc(m, origType, sig)
20052008
m.s[cfsTypeInit3].addFieldAssignment(tiNameForHcr(m, result), "marker", markerProc)
20062009
of tyPtr, tyRange, tyUncheckedArray: genTypeInfoAux(m, t, t, result, info)

tests/refc/m24844.nim

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
type
2+
S*[T] = ref object of RootObj
3+
k: string
4+
A*[T] = ref object of S[T]
5+
6+
proc p*[T](): S[T] = S[T]()
7+
proc u*() = discard A[int]()
8+
discard A[int]()

tests/refc/t24844.nim

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
discard """
2+
matrix: "--mm:refc; --mm:arc"
3+
joinable: false
4+
"""
5+
6+
import m24844
7+
8+
u()
9+
10+
type E = distinct int
11+
discard p[E]()

0 commit comments

Comments
 (0)