diff options
author | LemonBoy <LemonBoy@users.noreply.github.com> | 2018-08-17 00:34:27 +0200 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2018-08-17 00:34:27 +0200 |
commit | ac0f5c83ca0d2dba96827f07b9d7a99c107144e7 (patch) | |
tree | 4f4d8a63421a2c829ee310967c9216f9250e0ff1 /compiler/ccgstmts.nim | |
parent | af037546b0b8fb77a9bd33c6f75f6c7c216fa9bb (diff) | |
download | Nim-ac0f5c83ca0d2dba96827f07b9d7a99c107144e7.tar.gz |
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
Diffstat (limited to 'compiler/ccgstmts.nim')
-rw-r--r-- | compiler/ccgstmts.nim | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/compiler/ccgstmts.nim b/compiler/ccgstmts.nim index 81e3fe4a7..a7a2b3fee 100644 --- a/compiler/ccgstmts.nim +++ b/compiler/ccgstmts.nim @@ -256,7 +256,15 @@ proc genSingleVar(p: BProc, a: PNode) = # That's why we are doing the construction inside the preInitProc. # genObjectInit relies on the C runtime's guarantees that # global variables will be initialized to zero. - genObjectInit(p.module.preInitProc, cpsInit, v.typ, v.loc, true) + var loc = v.loc + + # When the native TLS is unavailable, a global thread-local variable needs + # one more layer of indirection in order to access the TLS block. + # Only do this for complex types that may need a call to `objectInit` + if sfThread in v.flags and emulatedThreadVars(p.config) and + isComplexValueType(v.typ): + initLocExprSingleUse(p.module.preInitProc, vn, loc) + genObjectInit(p.module.preInitProc, cpsInit, v.typ, loc, true) # Alternative construction using default constructor (which may zeromem): # if sfImportc notin v.flags: constructLoc(p.module.preInitProc, v.loc) if sfExportc in v.flags and p.module.g.generatedHeader != nil: |