From a3d32a4176539d0829a4e868f4b005a1a71eb7ee Mon Sep 17 00:00:00 2001 From: Bung Date: Sat, 5 Nov 2022 19:22:16 +0800 Subject: [PATCH] fix arc global variable issues (#20759) * temp * unsure --- compiler/injectdestructors.nim | 7 +++++-- tests/arc/tarcmisc.nim | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/compiler/injectdestructors.nim b/compiler/injectdestructors.nim index ad43e23fcc..eda73eeb53 100644 --- a/compiler/injectdestructors.nim +++ b/compiler/injectdestructors.nim @@ -490,8 +490,11 @@ proc pVarTopLevel(v: PNode; c: var Con; s: var Scope; res: PNode) = res.add newTree(nkFastAsgn, v, genDefaultCall(v.typ, c, v.info)) elif sfThread notin v.sym.flags and sfCursor notin v.sym.flags: # do not destroy thread vars for now at all for consistency. - if sfGlobal in v.sym.flags and s.parent == nil: #XXX: Rethink this logic (see tarcmisc.test2) - c.graph.globalDestructors.add c.genDestroy(v) + if sfGlobal in v.sym.flags: #XXX: Rethink this logic (see tarcmisc.test2) + if c.inLoop > 0: + s.final.add c.genDestroy(v) + else: + c.graph.globalDestructors.add c.genDestroy(v) else: s.final.add c.genDestroy(v) diff --git a/tests/arc/tarcmisc.nim b/tests/arc/tarcmisc.nim index 567daf9823..3160d8a4df 100644 --- a/tests/arc/tarcmisc.nim +++ b/tests/arc/tarcmisc.nim @@ -124,7 +124,7 @@ proc test(count: int) = test(3) proc test2(count: int) = - #block: #XXX: Fails with block currently + block: #XXX: Fails with block currently var v {.global.} = newVariable(20) var count = count - 1