-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixes #24305, refs #23807 Since #23014 `nkHiddenAddr` is produced to fast assign array elements in iterators. However the array access inside this `nkHiddenAddr` can get folded at compile time, generating invalid code. In #23807, compile time folding of regular `addr` expressions was changed to be prevented in `transf` but `nkHiddenAddr` was not updated alongside it. The method for preventing folding in `addr` in #23807 was also faulty, it should only trigger on the immediate child node of the address rather than all nodes nested inside it. This caused a regression as outlined in [this comment](#24322 (comment)). To fix both issues, `addr` and `nkHiddenAddr` now both shallowly prevent constant folding for their immediate children. (cherry picked from commit 52cf7df)
- Loading branch information
Showing
2 changed files
with
41 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
discard """ | ||
output: ''' | ||
23 | ||
23 | ||
23 | ||
23 | ||
23 | ||
23 | ||
''' | ||
""" | ||
|
||
block: # issue #24305 | ||
iterator demo(a: openArray[int]): int = | ||
for k in countUp(a[0], 19): | ||
yield 23 | ||
|
||
for k in demo(@[17]): | ||
echo k | ||
|
||
block: # issue #24305 with array | ||
iterator demo(a: array[1, int]): int = | ||
for k in countUp(a[0], 19): | ||
yield 23 | ||
|
||
for k in demo([17]): | ||
echo k | ||
|
||
block: # related regression | ||
proc main = | ||
let a = [0, 1, 2] | ||
let x = addr a[low(a)] | ||
main() |