fixes #26119; stack usage increase on try/except expression (#26166)

fixes #26119
This commit is contained in:
ringabout
2026-09-04 14:18:07 +08:00
committed by GitHub
parent 973065b279
commit 641243b70e
2 changed files with 26 additions and 0 deletions

View File

@@ -787,6 +787,12 @@ template handleNestedTempl(n, processCall: untyped, willProduceStmt = false,
result = nil
assert(false)
if willProduceStmt:
# The value is now produced by statements in the branches. Keeping the
# control-flow node's expression type would make code generators allocate
# a second, unused destination for it.
result.typ = nil
proc pRaiseStmt(n: PNode, c: var Con; s: var Scope): PNode =
if optOwnedRefs in c.graph.config.globalOptions and n[0].kind != nkEmpty:
if n[0].kind in nkCallKinds:

20
tests/ccgbugs/t26119.nim Normal file
View File

@@ -0,0 +1,20 @@
discard """
targets: "c cpp"
matrix: "--mm:refc; --mm:orc"
ccodeCheck: "\\i !@('W T' \\d+ '_;')"
"""
type W {.exportc.} = object
data: array[1000, byte]
items: seq[int]
# bug #26119: assigning a try expression directly to the result must not leave
# an unused temporary of the result type in the generated procedure.
proc y(): W {.exportc.} =
try:
default(W)
except CatchableError:
default(W)
var v = y()
doAssert v.data[0] == 0 and v.items.len == 0