This commit is contained in:
Andreas Rumpf
2026-03-16 16:56:18 +01:00
committed by GitHub
parent 797b05eda6
commit d0919b6df8
2 changed files with 39 additions and 19 deletions

View File

@@ -559,17 +559,21 @@ block: # void iterator
discard
var a = it
block: # Locals present in only 1 state should be on the stack
block:
# Locals present in only 1 state should be on the stack
proc checkOnStack(a: pointer, shouldBeOnStack: bool) =
# Quick and dirty way to check if a points to stack
var dummy = 0
let dummyAddr = addr dummy
let distance = abs(cast[int](dummyAddr) - cast[int](a))
const requiredDistance = 300
if shouldBeOnStack:
doAssert(distance <= requiredDistance, "a is not on stack, but should")
else:
doAssert(distance > requiredDistance, "a is on stack, but should not")
# bug #25596: the very fact we take the address prevents the local
# from being on the stack
when false:
# Quick and dirty way to check if a points to stack
var dummy = 0
let dummyAddr = addr dummy
let distance = abs(cast[int](dummyAddr) - cast[int](a))
const requiredDistance = 300
if shouldBeOnStack:
doAssert(distance <= requiredDistance, "a is not on stack, but should")
else:
doAssert(distance > requiredDistance, "a is on stack, but should not")
iterator it(): int {.closure.} =
var a = 1