summary refs log tree commit diff stats
path: root/compiler
diff options
context:
space:
mode:
authorZahary Karadjov <zahary@gmail.com>2013-05-25 19:38:41 +0300
committerZahary Karadjov <zahary@gmail.com>2013-05-26 11:14:23 +0300
commit420789c2782be7b969ad02448841d90bd0d17a1f (patch)
tree32e7a792489a2af529b8cc475291b7424dad80fc /compiler
parent7fccdedcb5d1e583039b2ea2ae6564412a0f5104 (diff)
downloadNim-420789c2782be7b969ad02448841d90bd0d17a1f.tar.gz
bugfix: emulated thread vars used in combination with the mark & sweep GC
resulted in invalid code generation
Diffstat (limited to 'compiler')
-rw-r--r--compiler/ccgthreadvars.nim4
-rw-r--r--compiler/ccgtrav.nim8
-rw-r--r--compiler/cgen.nim3
3 files changed, 11 insertions, 4 deletions
diff --git a/compiler/ccgthreadvars.nim b/compiler/ccgthreadvars.nim
index 4785402e7..d312ea027 100644
--- a/compiler/ccgthreadvars.nim
+++ b/compiler/ccgthreadvars.nim
@@ -12,10 +12,10 @@
 
 # included from cgen.nim
 
-proc emulatedThreadVars(): bool {.inline.} =
+proc emulatedThreadVars(): bool =
   result = {optThreads, optTlsEmulation} <= gGlobalOptions
 
-proc AccessThreadLocalVar(p: BProc, s: PSym) =
+proc accessThreadLocalVar(p: BProc, s: PSym) =
   if emulatedThreadVars() and not p.ThreadVarAccessed:
     p.ThreadVarAccessed = true
     p.module.usesThreadVars = true
diff --git a/compiler/ccgtrav.nim b/compiler/ccgtrav.nim
index aa8b85600..9534eae91 100644
--- a/compiler/ccgtrav.nim
+++ b/compiler/ccgtrav.nim
@@ -127,18 +127,22 @@ proc genTraverseProc(m: BModule, typ: PType, reason: TTypeInfoReason): PRope =
   m.s[cfsProcHeaders].appf("$1;$n", header)
   m.s[cfsProcs].app(generatedProc)
 
-
 proc genTraverseProcForGlobal(m: BModule, s: PSym): PRope =
   discard genTypeInfo(m, s.loc.t)
   
   var c: TTraversalClosure
   var p = newProc(nil, m)
+  var sLoc = s.loc.r
   result = getGlobalTempName()
   
+  if sfThread in s.flags and emulatedThreadVars():
+    accessThreadLocalVar(p, s)
+    sLoc = con("NimTV->", sLoc)
+    
   c.visitorFrmt = "#nimGCvisit((void*)$1, 0);$n"
   c.p = p
   let header = ropef("N_NIMCALL(void, $1)()", result)
-  genTraverseProc(c, s.loc.r, s.loc.t)
+  genTraverseProc(c, sLoc, s.loc.t)
   
   let generatedProc = ropef("$1 {$n$2$3$4}$n",
         [header, p.s(cpsLocals), p.s(cpsInit), p.s(cpsStmts)])
diff --git a/compiler/cgen.nim b/compiler/cgen.nim
index 92216d278..f552b95ea 100644
--- a/compiler/cgen.nim
+++ b/compiler/cgen.nim
@@ -284,6 +284,9 @@ proc genLineDir(p: BProc, t: PNode) =
     linefmt(p, cpsStmts, "nimln($1, $2);$n",
             line.toRope, t.info.quotedFilename)
 
+proc accessThreadLocalVar(p: BProc, s: PSym)
+proc emulatedThreadVars(): bool {.inline.}
+
 include "ccgtypes.nim"
 
 # ------------------------------ Manager of temporaries ------------------