Fixes 8535 (#8591)

* Goodbye postInitProc

* Give preInitProc its own scope

Avoid any conflict between the variables introduced by preInitProc and
initProc since both are codegen'd in the same function body.

* Fix codegen for global var init in emulated TLS

Fixes #8535

* Add test for #8535

* Keep a bogus stack frame around

* Remove more dead code
This commit is contained in:
LemonBoy 2018-08-17 00:34:27 +02:00 • committed by Andreas Rumpf
commit ac0f5c83ca
4 changed files with 45 additions and 16 deletions

View file

@ -1136,12 +1136,29 @@ proc genInitCode(m: BModule) =
appcg(m, m.s[cfsTypeInit1], "static #TNimType $1[$2];$n",
[m.nimTypesName, rope(m.nimTypes)])
# Give this small function its own scope
addf(prc, "{$N", [])
block:
# Keep a bogus frame in case the code needs one
add(prc, ~"\tTFrame FR_; FR_.len = 0;$N")
add(prc, genSectionStart(cpsLocals, m.config))
add(prc, m.preInitProc.s(cpsLocals))
add(prc, genSectionEnd(cpsLocals, m.config))
add(prc, genSectionStart(cpsInit, m.config))
add(prc, m.preInitProc.s(cpsInit))
add(prc, genSectionEnd(cpsInit, m.config))
add(prc, genSectionStart(cpsStmts, m.config))
add(prc, m.preInitProc.s(cpsStmts))
add(prc, genSectionEnd(cpsStmts, m.config))
addf(prc, "}$N", [])
add(prc, initGCFrame(m.initProc))
add(prc, genSectionStart(cpsLocals, m.config))
add(prc, m.preInitProc.s(cpsLocals))
add(prc, m.initProc.s(cpsLocals))
add(prc, m.postInitProc.s(cpsLocals))
add(prc, genSectionEnd(cpsLocals, m.config))
if optStackTrace in m.initProc.options and frameDeclared notin m.flags:
@ -1155,16 +1172,13 @@ proc genInitCode(m: BModule) =
add(prc, ~"\tTFrame FR_; FR_.len = 0;$N")
add(prc, genSectionStart(cpsInit, m.config))
add(prc, m.preInitProc.s(cpsInit))
add(prc, m.initProc.s(cpsInit))
add(prc, m.postInitProc.s(cpsInit))
add(prc, genSectionEnd(cpsInit, m.config))
add(prc, genSectionStart(cpsStmts, m.config))
add(prc, m.preInitProc.s(cpsStmts))
add(prc, m.initProc.s(cpsStmts))
add(prc, m.postInitProc.s(cpsStmts))
add(prc, genSectionEnd(cpsStmts, m.config))
if optStackTrace in m.initProc.options and preventStackTrace notin m.flags:
add(prc, deinitFrame(m.initProc))
add(prc, deinitGCFrame(m.initProc))
@ -1210,11 +1224,6 @@ proc newPreInitProc(m: BModule): BProc =
# little hack so that unique temporaries are generated:
result.labels = 100_000
proc newPostInitProc(m: BModule): BProc =
result = newProc(nil, m)
# little hack so that unique temporaries are generated:
result.labels = 200_000
proc initProcOptions(m: BModule): TOptions =
let opts = m.config.options
if sfSystemModule in m.module.flags: opts-{optStackTrace} else: opts
@ -1236,7 +1245,6 @@ proc rawNewModule(g: BModuleList; module: PSym, filename: string): BModule =
result.initProc = newProc(nil, result)
result.initProc.options = initProcOptions(result)
result.preInitProc = newPreInitProc(result)
result.postInitProc = newPostInitProc(result)
initNodeTable(result.dataCache)
result.typeStack = @[]
result.forwardedProcs = @[]
@ -1247,7 +1255,6 @@ proc rawNewModule(g: BModuleList; module: PSym, filename: string): BModule =
if sfSystemModule in module.flags:
incl result.flags, preventStackTrace
excl(result.preInitProc.options, optStackTrace)
excl(result.postInitProc.options, optStackTrace)
let ndiName = if optCDebug in g.config.globalOptions: changeFileExt(completeCFilePath(g.config, filename), "ndi")
else: ""
open(result.ndi, ndiName, g.config)
@ -1265,7 +1272,6 @@ proc resetModule*(m: BModule) =
m.initProc = newProc(nil, m)
m.initProc.options = initProcOptions(m)
m.preInitProc = newPreInitProc(m)
m.postInitProc = newPostInitProc(m)
initNodeTable(m.dataCache)
m.typeStack = @[]
m.forwardedProcs = @[]