fixes a critical =trace generation bug (see test case) (#14140)

This commit is contained in:
Andreas Rumpf 2020-04-27 22:20:14 +02:00 • committed by GitHub
commit 065a6af2de
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 2 deletions

View file

@ -253,9 +253,13 @@ proc newOpCall(op: PSym; x: PNode): PNode =
proc newDeepCopyCall(op: PSym; x, y: PNode): PNode = proc newDeepCopyCall(op: PSym; x, y: PNode): PNode =
result = newAsgnStmt(x, newOpCall(op, y)) result = newAsgnStmt(x, newOpCall(op, y))
proc usesBuiltinArc(t: PType): bool =
proc wrap(t: PType): bool {.nimcall.} = ast.isGCedMem(t)
result = types.searchTypeFor(t, wrap)
proc useNoGc(c: TLiftCtx; t: PType): bool {.inline.} = proc useNoGc(c: TLiftCtx; t: PType): bool {.inline.} =
result = optSeqDestructors in c.g.config.globalOptions and result = optSeqDestructors in c.g.config.globalOptions and
({tfHasGCedMem, tfHasOwned} * t.flags != {} or t.isGCedMem) ({tfHasGCedMem, tfHasOwned} * t.flags != {} or usesBuiltinArc(t))
proc requiresDestructor(c: TLiftCtx; t: PType): bool {.inline.} = proc requiresDestructor(c: TLiftCtx; t: PType): bool {.inline.} =
result = optSeqDestructors in c.g.config.globalOptions and result = optSeqDestructors in c.g.config.globalOptions and

View file

@ -253,7 +253,7 @@ proc searchTypeForAux(t: PType, predicate: TTypePredicate,
else: else:
discard discard
proc searchTypeFor(t: PType, predicate: TTypePredicate): bool = proc searchTypeFor*(t: PType, predicate: TTypePredicate): bool =
var marker = initIntSet() var marker = initIntSet()
result = searchTypeForAux(t, predicate, marker) result = searchTypeForAux(t, predicate, marker)

View file

@ -13,8 +13,24 @@ proc main(x: int) =
let m = n let m = n
n.kids.add m n.kids.add m
type
NodeA = ref object
s: char
a: array[3, NodeA]
proc m: NodeA =
result = NodeA(s: 'a')
result.a[0] = result
result.a[1] = result
result.a[2] = result
proc mainA =
for i in 0..10:
discard m()
let mem = getOccupiedMem() let mem = getOccupiedMem()
main(90) main(90)
mainA()
GC_fullCollect() GC_fullCollect()
echo "MEM ", getOccupiedMem() - mem echo "MEM ", getOccupiedMem() - mem