destructors: don't produce stupid code for 'cast' (#14208) [backport:1.2]
* destructors: don't produce stupid code for 'cast' * fixes #14207
This commit is contained in:
parent
3e060cfb0a
commit
b6fb609e0d
3 changed files with 22 additions and 4 deletions
|
|
@ -541,8 +541,8 @@ template genNoReturn(c: var Con; n: PNode) =
|
||||||
c.code.add Instr(n: n, kind: goto, dest: high(int) - c.code.len)
|
c.code.add Instr(n: n, kind: goto, dest: high(int) - c.code.len)
|
||||||
|
|
||||||
proc genRaise(c: var Con; n: PNode) =
|
proc genRaise(c: var Con; n: PNode) =
|
||||||
genJoins(c, n)
|
|
||||||
gen(c, n[0])
|
gen(c, n[0])
|
||||||
|
genJoins(c, n)
|
||||||
if c.inTryStmt > 0:
|
if c.inTryStmt > 0:
|
||||||
c.tryStmtFixups.add c.gotoI(n)
|
c.tryStmtFixups.add c.gotoI(n)
|
||||||
else:
|
else:
|
||||||
|
|
@ -553,11 +553,11 @@ proc genImplicitReturn(c: var Con) =
|
||||||
gen(c, c.owner.ast[resultPos])
|
gen(c, c.owner.ast[resultPos])
|
||||||
|
|
||||||
proc genReturn(c: var Con; n: PNode) =
|
proc genReturn(c: var Con; n: PNode) =
|
||||||
genJoins(c, n)
|
|
||||||
if n[0].kind != nkEmpty:
|
if n[0].kind != nkEmpty:
|
||||||
gen(c, n[0])
|
gen(c, n[0])
|
||||||
else:
|
else:
|
||||||
genImplicitReturn(c)
|
genImplicitReturn(c)
|
||||||
|
genJoins(c, n)
|
||||||
genNoReturn(c, n)
|
genNoReturn(c, n)
|
||||||
|
|
||||||
const
|
const
|
||||||
|
|
|
||||||
|
|
@ -957,6 +957,10 @@ proc p(n: PNode; c: var Con; mode: ProcessMode): PNode =
|
||||||
for i in 0..<n.len:
|
for i in 0..<n.len:
|
||||||
result[i] = p(n[i], c, mode)
|
result[i] = p(n[i], c, mode)
|
||||||
inc c.hasUnstructuredCf
|
inc c.hasUnstructuredCf
|
||||||
|
of nkCast:
|
||||||
|
result = shallowCopy(n)
|
||||||
|
result[0] = n[0]
|
||||||
|
result[1] = p(n[1], c, mode)
|
||||||
else:
|
else:
|
||||||
result = shallowCopy(n)
|
result = shallowCopy(n)
|
||||||
for i in 0..<n.len:
|
for i in 0..<n.len:
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
discard """
|
discard """
|
||||||
output: '''
|
output: '''
|
||||||
|
123xyzabc
|
||||||
destroyed: false
|
destroyed: false
|
||||||
destroyed: false
|
destroyed: false
|
||||||
closed
|
closed
|
||||||
|
|
@ -8,6 +9,19 @@ destroying variable
|
||||||
cmd: "nim c --gc:arc $file"
|
cmd: "nim c --gc:arc $file"
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
proc takeSink(x: sink string): bool = true
|
||||||
|
|
||||||
|
proc b(x: sink string): string =
|
||||||
|
if takeSink(x):
|
||||||
|
return x & "abc"
|
||||||
|
|
||||||
|
proc bbb(inp: string) =
|
||||||
|
let y = inp & "xyz"
|
||||||
|
echo b(y)
|
||||||
|
|
||||||
|
bbb("123")
|
||||||
|
|
||||||
|
|
||||||
# bug #13691
|
# bug #13691
|
||||||
type Variable = ref object
|
type Variable = ref object
|
||||||
value: int
|
value: int
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue