This commit is contained in:
Andreas Rumpf
2016-09-07 08:29:37 +02:00
parent 87eb3a105d
commit 08a6f3fc67
4 changed files with 33 additions and 8 deletions

View File

@@ -293,6 +293,8 @@ proc genIf(p: BProc, n: PNode, d: var TLoc) =
genLineDir(p, n)
let lend = getLabel(p)
for i in countup(0, sonsLen(n) - 1):
# bug #4230: avoid false sharing between branches:
if d.k == locTemp and isEmptyType(n.typ): d.k = locNone
let it = n.sons[i]
if it.len == 2:
when newScopeForIf: startBlock(p)
@@ -488,16 +490,20 @@ proc genWhileStmt(p: BProc, t: PNode) =
dec(p.withinLoop)
proc genBlock(p: BProc, t: PNode, d: var TLoc) =
proc genBlock(p: BProc, n: PNode, d: var TLoc) =
# bug #4505: allocate the temp in the outer scope
# so that it can escape the generated {}:
if not isEmptyType(n.typ) and d.k == locNone:
getTemp(p, n.typ, d)
preserveBreakIdx:
p.breakIdx = startBlock(p)
if t.sons[0].kind != nkEmpty:
if n.sons[0].kind != nkEmpty:
# named block?
assert(t.sons[0].kind == nkSym)
var sym = t.sons[0].sym
assert(n.sons[0].kind == nkSym)
var sym = n.sons[0].sym
sym.loc.k = locOther
sym.position = p.breakIdx+1
expr(p, t.sons[1], d)
expr(p, n.sons[1], d)
endBlock(p)
proc genParForStmt(p: BProc, t: PNode) =
@@ -592,6 +598,8 @@ proc genCaseSecondPass(p: BProc, t: PNode, d: var TLoc,
labId, until: int): TLabel =
var lend = getLabel(p)
for i in 1..until:
# bug #4230: avoid false sharing between branches:
if d.k == locTemp and isEmptyType(t.typ): d.k = locNone
lineF(p, cpsStmts, "LA$1: ;$n", [rope(labId + i)])
if t.sons[i].kind == nkOfBranch:
var length = sonsLen(t.sons[i])
@@ -727,6 +735,8 @@ proc genOrdinalCase(p: BProc, n: PNode, d: var TLoc) =
lineF(p, cpsStmts, "switch ($1) {$n", [rdCharLoc(a)])
var hasDefault = false
for i in splitPoint+1 .. < n.len:
# bug #4230: avoid false sharing between branches:
if d.k == locTemp and isEmptyType(n.typ): d.k = locNone
var branch = n[i]
if branch.kind == nkOfBranch:
genCaseRange(p, branch)
@@ -797,6 +807,8 @@ proc genTryCpp(p: BProc, t: PNode, d: var TLoc) =
var i = 1
var catchAllPresent = false
while (i < length) and (t.sons[i].kind == nkExceptBranch):
# bug #4230: avoid false sharing between branches:
if d.k == locTemp and isEmptyType(t.typ): d.k = locNone
let blen = sonsLen(t.sons[i])
if i > 1: addf(p.s(cpsStmts), "else ", [])
if blen == 1:
@@ -902,6 +914,8 @@ proc genTry(p: BProc, t: PNode, d: var TLoc) =
inc p.inExceptBlock
var i = 1
while (i < length) and (t.sons[i].kind == nkExceptBranch):
# bug #4230: avoid false sharing between branches:
if d.k == locTemp and isEmptyType(t.typ): d.k = locNone
var blen = sonsLen(t.sons[i])
if blen == 1:
# general except section:

View File

@@ -323,8 +323,9 @@ proc initLocalVar(p: BProc, v: PSym, immediateAsgn: bool) =
proc getTemp(p: BProc, t: PType, result: var TLoc; needsInit=false) =
inc(p.labels)
result.r = "LOC" & rope(p.labels)
addf(p.blocks[0].sections[cpsLocals],
"$1 $2;$n", [getTypeDesc(p.module, t), result.r])
#addf(p.blocks[0].sections[cpsLocals],
# "$1 $2;$n", [getTypeDesc(p.module, t), result.r])
linefmt(p, cpsLocals, "$1 $2;$n", getTypeDesc(p.module, t), result.r)
result.k = locTemp
#result.a = - 1
result.t = t

View File

@@ -18,3 +18,14 @@ test proc() =
test proc() = discard
else:
test proc() = discard
# ensure 'case' does not trigger the same bug:
test proc() =
let f = 15
case f
of 10:
test proc() = discard
of 3:
test proc() = discard
else:
test proc() = discard

View File

@@ -53,7 +53,6 @@ Bugs
- VM: ptr/ref T cannot work in general
- blocks can "export" an identifier but the CCG generates {} for them ...
- ConcreteTypes in a 'case' means we don't check for duplicated case branches
- BUG: echo with template `$`*(info: TLineInfo): expr = toFileLineCol(info)
GC