fixes a codegen bug: in 'result = f(result)' the default initialization for 'result' IS required
This commit is contained in:
parent
7eaa2474a2
commit
740c07ead4
1 changed files with 8 additions and 1 deletions
|
|
@ -663,6 +663,13 @@ proc closureSetup(p: BProc, prc: PSym) =
|
||||||
linefmt(p, cpsStmts, "$1 = ($2) ClE_0;$n",
|
linefmt(p, cpsStmts, "$1 = ($2) ClE_0;$n",
|
||||||
rdLoc(env.loc), getTypeDesc(p.module, env.typ))
|
rdLoc(env.loc), getTypeDesc(p.module, env.typ))
|
||||||
|
|
||||||
|
proc containsResult(n: PNode): bool =
|
||||||
|
if n.kind == nkSym and n.sym.kind == skResult:
|
||||||
|
result = true
|
||||||
|
else:
|
||||||
|
for i in 0..<n.safeLen:
|
||||||
|
if containsResult(n[i]): return true
|
||||||
|
|
||||||
proc easyResultAsgn(n: PNode): PNode =
|
proc easyResultAsgn(n: PNode): PNode =
|
||||||
const harmless = {nkConstSection, nkTypeSection, nkEmpty, nkCommentStmt} +
|
const harmless = {nkConstSection, nkTypeSection, nkEmpty, nkCommentStmt} +
|
||||||
declarativeDefs
|
declarativeDefs
|
||||||
|
|
@ -672,7 +679,7 @@ proc easyResultAsgn(n: PNode): PNode =
|
||||||
while i < n.len and n[i].kind in harmless: inc i
|
while i < n.len and n[i].kind in harmless: inc i
|
||||||
if i < n.len: result = easyResultAsgn(n[i])
|
if i < n.len: result = easyResultAsgn(n[i])
|
||||||
of nkAsgn, nkFastAsgn:
|
of nkAsgn, nkFastAsgn:
|
||||||
if n[0].kind == nkSym and skResult == n[0].sym.kind:
|
if n[0].kind == nkSym and n[0].sym.kind == skResult and not containsResult(n[1]):
|
||||||
incl n.flags, nfPreventCg
|
incl n.flags, nfPreventCg
|
||||||
return n[1]
|
return n[1]
|
||||||
of nkReturnStmt:
|
of nkReturnStmt:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue