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`

(cherry picked from commit a77d1cc6c1)
This commit is contained in:
ringabout
2025-09-15 21:03:22 +08:00
committed by narimiran
parent 4c7ddcd79a
commit 2fc23370ec
3 changed files with 22 additions and 0 deletions

View File

@@ -1886,6 +1886,9 @@ proc genTypeInfoV1(m: BModule; t: PType; info: TLineInfo): Rope =
of tyRef:
genTypeInfoAux(m, t, t, result, info)
if m.config.selectedGC in {gcMarkAndSweep, gcRefc, gcGo}:
# it may not be used in other places except in `genTraverseProc`,
# we have to generate a typedesc for this case, not a weak one
discard getTypeDesc(m, origType.last)
let markerProc = genTraverseProc(m, origType, sig)
m.s[cfsTypeInit3].addf("$1.marker = $2;$n", [tiNameForHcr(m, result), markerProc])
of tyPtr, tyRange, tyUncheckedArray: genTypeInfoAux(m, t, t, result, info)

8
tests/refc/m24844.nim Normal file
View File

@@ -0,0 +1,8 @@
type
S*[T] = ref object of RootObj
k: string
A*[T] = ref object of S[T]
proc p*[T](): S[T] = S[T]()
proc u*() = discard A[int]()
discard A[int]()

11
tests/refc/t24844.nim Normal file
View File

@@ -0,0 +1,11 @@
discard """
matrix: "--mm:refc; --mm:arc"
joinable: false
"""
import m24844
u()
type E = distinct int
discard p[E]()