fixes #6955
This commit is contained in:
parent
49a5213713
commit
f55d094cf2
2 changed files with 17 additions and 4 deletions
|
|
@ -572,10 +572,14 @@ proc isNoEffectList(n: PNode): bool {.inline.} =
|
||||||
assert n.kind == nkEffectList
|
assert n.kind == nkEffectList
|
||||||
n.len == 0 or (n[tagEffects] == nil and n[exceptionEffects] == nil)
|
n.len == 0 or (n[tagEffects] == nil and n[exceptionEffects] == nil)
|
||||||
|
|
||||||
proc trackOperand(tracked: PEffects, n: PNode, paramType: PType) =
|
proc isTrival(caller: PNode): bool {.inline.} =
|
||||||
|
result = caller.kind == nkSym and caller.sym.magic in {mEqProc, mIsNil}
|
||||||
|
|
||||||
|
proc trackOperand(tracked: PEffects, n: PNode, paramType: PType; caller: PNode) =
|
||||||
let a = skipConvAndClosure(n)
|
let a = skipConvAndClosure(n)
|
||||||
let op = a.typ
|
let op = a.typ
|
||||||
if op != nil and op.kind == tyProc and n.skipConv.kind != nkNilLit:
|
# assume indirect calls are taken here:
|
||||||
|
if op != nil and op.kind == tyProc and n.skipConv.kind != nkNilLit and not isTrival(caller):
|
||||||
internalAssert tracked.config, op.n.sons[0].kind == nkEffectList
|
internalAssert tracked.config, op.n.sons[0].kind == nkEffectList
|
||||||
var effectList = op.n.sons[0]
|
var effectList = op.n.sons[0]
|
||||||
var s = n.skipConv
|
var s = n.skipConv
|
||||||
|
|
@ -773,7 +777,7 @@ proc track(tracked: PEffects, n: PNode) =
|
||||||
if not (a.kind == nkSym and a.sym == tracked.owner):
|
if not (a.kind == nkSym and a.sym == tracked.owner):
|
||||||
markSideEffect(tracked, a)
|
markSideEffect(tracked, a)
|
||||||
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))
|
for i in 1 ..< len(n): 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]
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,18 @@
|
||||||
discard """
|
discard """
|
||||||
errormsg: "'mainUnsafe' is not GC-safe"
|
errormsg: "'mainUnsafe' is not GC-safe"
|
||||||
line: 17
|
line: 26
|
||||||
cmd: "nim $target --hints:on --threads:on $options $file"
|
cmd: "nim $target --hints:on --threads:on $options $file"
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# bug #6955
|
||||||
|
var global_proc: proc(a: string): int {.nimcall.} = nil
|
||||||
|
|
||||||
|
proc myproc(i: int) {.gcsafe.} =
|
||||||
|
if global_proc != nil:
|
||||||
|
echo "a"
|
||||||
|
if isNil(global_proc):
|
||||||
|
return
|
||||||
|
|
||||||
proc mymap(x: proc ()) =
|
proc mymap(x: proc ()) =
|
||||||
x()
|
x()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue