fixes #11050
This commit is contained in:
parent
850e90ac30
commit
7640a230fc
3 changed files with 34 additions and 7 deletions
|
|
@ -738,7 +738,7 @@ proc track(tracked: PEffects, n: PNode) =
|
||||||
mergeTags(tracked, effectList.sons[tagEffects], n)
|
mergeTags(tracked, effectList.sons[tagEffects], n)
|
||||||
gcsafeAndSideeffectCheck()
|
gcsafeAndSideeffectCheck()
|
||||||
if a.kind != nkSym or a.sym.magic != mNBindSym:
|
if a.kind != nkSym or a.sym.magic != mNBindSym:
|
||||||
for i in 1 ..< len(n): trackOperand(tracked, n.sons[i], paramType(op, i), a)
|
for i in 1 ..< n.len: trackOperand(tracked, n.sons[i], paramType(op, i), a)
|
||||||
if a.kind == nkSym and a.sym.magic in {mNew, mNewFinalize, mNewSeq}:
|
if a.kind == nkSym and a.sym.magic in {mNew, mNewFinalize, mNewSeq}:
|
||||||
# may not look like an assignment, but it is:
|
# may not look like an assignment, but it is:
|
||||||
let arg = n.sons[1]
|
let arg = n.sons[1]
|
||||||
|
|
@ -754,7 +754,7 @@ proc track(tracked: PEffects, n: PNode) =
|
||||||
track(tracked, n.sons[i])
|
track(tracked, n.sons[i])
|
||||||
of nkDotExpr:
|
of nkDotExpr:
|
||||||
guardDotAccess(tracked, n)
|
guardDotAccess(tracked, n)
|
||||||
for i in 0 ..< len(n): track(tracked, n.sons[i])
|
for i in 0 ..< n.len: track(tracked, n.sons[i])
|
||||||
of nkCheckedFieldExpr:
|
of nkCheckedFieldExpr:
|
||||||
track(tracked, n.sons[0])
|
track(tracked, n.sons[0])
|
||||||
if warnProveField in tracked.config.notes:
|
if warnProveField in tracked.config.notes:
|
||||||
|
|
@ -821,7 +821,7 @@ proc track(tracked: PEffects, n: PNode) =
|
||||||
of nkForStmt, nkParForStmt:
|
of nkForStmt, nkParForStmt:
|
||||||
# we are very conservative here and assume the loop is never executed:
|
# we are very conservative here and assume the loop is never executed:
|
||||||
let oldState = tracked.init.len
|
let oldState = tracked.init.len
|
||||||
for i in 0 .. len(n)-3:
|
for i in 0 .. n.len-3:
|
||||||
let it = n[i]
|
let it = n[i]
|
||||||
track(tracked, it)
|
track(tracked, it)
|
||||||
if tracked.owner.kind != skMacro:
|
if tracked.owner.kind != skMacro:
|
||||||
|
|
@ -830,13 +830,19 @@ proc track(tracked: PEffects, n: PNode) =
|
||||||
createTypeBoundOps(tracked.c, x.typ, x.info)
|
createTypeBoundOps(tracked.c, x.typ, x.info)
|
||||||
else:
|
else:
|
||||||
createTypeBoundOps(tracked.c, it.typ, it.info)
|
createTypeBoundOps(tracked.c, it.typ, it.info)
|
||||||
for i in len(n)-2..len(n)-1:
|
let iterCall = n[n.len-2]
|
||||||
track(tracked, n.sons[i])
|
let loopBody = n[n.len-1]
|
||||||
|
if tracked.owner.kind != skMacro and iterCall.len > 1:
|
||||||
|
# XXX this is a bit hacky:
|
||||||
|
if iterCall[1].typ.skipTypes(abstractVar).kind notin {tyVarargs, tyOpenArray}:
|
||||||
|
createTypeBoundOps(tracked.c, iterCall[1].typ, iterCall[1].info)
|
||||||
|
track(tracked, iterCall)
|
||||||
|
track(tracked, loopBody)
|
||||||
setLen(tracked.init, oldState)
|
setLen(tracked.init, oldState)
|
||||||
of nkObjConstr:
|
of nkObjConstr:
|
||||||
when false: track(tracked, n.sons[0])
|
when false: track(tracked, n.sons[0])
|
||||||
let oldFacts = tracked.guards.s.len
|
let oldFacts = tracked.guards.s.len
|
||||||
for i in 1 ..< len(n):
|
for i in 1 ..< n.len:
|
||||||
let x = n.sons[i]
|
let x = n.sons[i]
|
||||||
track(tracked, x)
|
track(tracked, x)
|
||||||
if x.sons[0].kind == nkSym and sfDiscriminant in x.sons[0].sym.flags:
|
if x.sons[0].kind == nkSym and sfDiscriminant in x.sons[0].sym.flags:
|
||||||
|
|
|
||||||
|
|
@ -651,6 +651,8 @@ proc transformFor(c: PTransf, n: PNode): PTransNode =
|
||||||
var t = formal.typ
|
var t = formal.typ
|
||||||
if formal.ast != nil and formal.ast.typ.destructor != nil and t.destructor == nil:
|
if formal.ast != nil and formal.ast.typ.destructor != nil and t.destructor == nil:
|
||||||
t = formal.ast.typ # better use the type that actually has a destructor.
|
t = formal.ast.typ # better use the type that actually has a destructor.
|
||||||
|
elif t.destructor == nil and arg.typ.destructor != nil:
|
||||||
|
t = arg.typ
|
||||||
# generate a temporary and produce an assignment statement:
|
# generate a temporary and produce an assignment statement:
|
||||||
var temp = newTemp(c, t, formal.info)
|
var temp = newTemp(c, t, formal.info)
|
||||||
#temp.sym.flags.incl sfCursor
|
#temp.sym.flags.incl sfCursor
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,8 @@ discard """
|
||||||
ho
|
ho
|
||||||
ha
|
ha
|
||||||
@["arg", "asdfklasdfkl", "asdkfj", "dfasj", "klfjl"]
|
@["arg", "asdfklasdfkl", "asdkfj", "dfasj", "klfjl"]
|
||||||
22 22'''
|
@[1, 2, 3]
|
||||||
|
25 25'''
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import allocators
|
import allocators
|
||||||
|
|
@ -132,6 +133,24 @@ proc other =
|
||||||
|
|
||||||
other()
|
other()
|
||||||
|
|
||||||
|
# bug #11050
|
||||||
|
|
||||||
|
type
|
||||||
|
Obj* = object
|
||||||
|
f*: seq[int]
|
||||||
|
|
||||||
|
method main(o: Obj) =
|
||||||
|
for newb in o.f:
|
||||||
|
discard
|
||||||
|
|
||||||
|
# test that o.f was not moved!
|
||||||
|
proc testforNoMove =
|
||||||
|
var o = Obj(f: @[1, 2, 3])
|
||||||
|
main(o)
|
||||||
|
echo o.f
|
||||||
|
|
||||||
|
testforNoMove()
|
||||||
|
|
||||||
#echo s
|
#echo s
|
||||||
let (a, d) = allocCounters()
|
let (a, d) = allocCounters()
|
||||||
discard cprintf("%ld %ld\n", a, d)
|
discard cprintf("%ld %ld\n", a, d)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue