fixes #17085 [backport:1.2] (#17101)

(cherry picked from commit 4395a26764)
This commit is contained in:
Andreas Rumpf
2021-02-19 12:30:39 +01:00
committed by narimiran
parent a48abc262c
commit ca1f97951c
4 changed files with 26 additions and 3 deletions

View File

@@ -25,10 +25,10 @@ proc getTraverseProc(p: BProc, v: PSym): Rope =
proc registerTraverseProc(p: BProc, v: PSym, traverseProc: Rope) =
if sfThread in v.flags:
appcg(p.module, p.module.initProc.procSec(cpsInit),
appcg(p.module, p.module.preInitProc.procSec(cpsInit),
"$n\t#nimRegisterThreadLocalMarker($1);$n$n", [traverseProc])
else:
appcg(p.module, p.module.initProc.procSec(cpsInit),
appcg(p.module, p.module.preInitProc.procSec(cpsInit),
"$n\t#nimRegisterGlobalMarker($1);$n$n", [traverseProc])
proc isAssignedImmediately(conf: ConfigRef; n: PNode): bool {.inline.} =

View File

@@ -1645,7 +1645,7 @@ proc genInitCode(m: BModule) =
writeSection(preInitProc, cpsLocals)
writeSection(preInitProc, cpsInit, m.hcrOn)
writeSection(preInitProc, cpsStmts)
prc.addf("}$N", [])
prc.addf("}/* preInitProc end */$N", [])
# add new scope for following code, because old vcc compiler need variable
# be defined at the top of the block

View File

@@ -217,6 +217,7 @@ proc gcTests(r: var TResults, cat: Category, options: string) =
test "stackrefleak"
test "cyclecollector"
test "trace_globals"
proc longGCTests(r: var TResults, cat: Category, options: string) =
when defined(windows):

View File

@@ -0,0 +1,22 @@
discard """
output: '''10000000
10000000
10000000'''
"""
# bug #17085
proc init(): string =
for a in 0..<10000000:
result.add 'c'
proc f() =
var a {.global.} = init()
var b {.global.} = init()
var c {.global.} = init()
echo a.len
echo b.len
echo c.len
f()