From c2b223688d032947dbf9dd28760d9fe89745fe76 Mon Sep 17 00:00:00 2001 From: Araq Date: Thu, 27 Nov 2014 09:41:36 +0100 Subject: [PATCH] fixes #1539 --- compiler/cgen.nim | 4 +- compiler/sempass2.nim | 23 ++++-- doc/rst.txt | 110 ----------------------------- tests/ccgbugs/tmissingvolatile.nim | 20 ++++++ 4 files changed, 38 insertions(+), 119 deletions(-) delete mode 100644 doc/rst.txt create mode 100644 tests/ccgbugs/tmissingvolatile.nim diff --git a/compiler/cgen.nim b/compiler/cgen.nim index 51c426d792..c645b81aaf 100644 --- a/compiler/cgen.nim +++ b/compiler/cgen.nim @@ -506,9 +506,7 @@ proc assignLocalVar(p: BProc, s: PSym) = if sfRegister in s.flags: app(decl, " register") #elif skipTypes(s.typ, abstractInst).kind in GcTypeKinds: # app(decl, " GC_GUARD") - if sfVolatile in s.flags or (p.nestedTryStmts.len > 0 and - not p.module.compileToCpp): - app(decl, " volatile") + if sfVolatile in s.flags: app(decl, " volatile") appf(decl, " $1;$n", [s.loc.r]) else: decl = ropef(s.cgDeclFrmt & ";$n", decl, s.loc.r) diff --git a/compiler/sempass2.nim b/compiler/sempass2.nim index 0d8c7c4799..f41e169e32 100644 --- a/compiler/sempass2.nim +++ b/compiler/sempass2.nim @@ -69,7 +69,7 @@ type TEffects = object exc: PNode # stack of exceptions tags: PNode # list of tags - bottom: int + bottom, inTryStmt: int owner: PSym init: seq[int] # list of initialized variables guards: TModel # nested guards @@ -165,10 +165,17 @@ proc guardDotAccess(a: PEffects; n: PNode) = else: guardGlobal(a, n, g) -proc initVar(a: PEffects, n: PNode) = +proc makeVolatile(a: PEffects; s: PSym) {.inline.} = + template compileToCpp(a): expr = + gCmd == cmdCompileToCpp or sfCompileToCpp in getModule(a.owner).flags + if a.inTryStmt > 0 and not compileToCpp(a): + incl(s.flags, sfVolatile) + +proc initVar(a: PEffects, n: PNode; volatileCheck: bool) = if n.kind != nkSym: return let s = n.sym if isLocalVar(a, s): + if volatileCheck: makeVolatile(a, s) for x in a.init: if x == s.id: return a.init.add s.id @@ -179,7 +186,9 @@ proc initVarViaNew(a: PEffects, n: PNode) = if {tfNeedsInit, tfNotNil} * s.typ.flags <= {tfNotNil}: # 'x' is not nil, but that doesn't mean its "not nil" children # are initialized: - initVar(a, n) + initVar(a, n, volatileCheck=true) + elif isLocalVar(a, s): + makeVolatile(a, s) proc warnAboutGcUnsafe(n: PNode) = #assert false @@ -304,7 +313,9 @@ proc trackTryStmt(tracked: PEffects, n: PNode) = let oldState = tracked.init.len var inter: TIntersection = @[] - track(tracked, n.sons[0]) + inc tracked.inTryStmt + track(tracked, n.sons[0]) + dec tracked.inTryStmt for i in oldState..