Bug 20900 – dmd crashes on static foreach over infinite range

Status
NEW
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2020-06-06T18:17:11Z
Last change time
2024-12-13T19:09:03Z
Assigned to
No Owner
Creator
Bolpat
Moved to GitHub: dmd#19716 →

Comments

Comment #0 by qs.il.paperinik — 2020-06-06T18:17:11Z
A quick and easy way to trigger the OutOfMemoryError struct SimpleRange { this(int front) { this.front = front; } bool empty = false; int front; void popFront() { } } void main() { static foreach (x; SimpleRange(1)) { } } While it is somewhat obvious that it cannot work, the compiler tells me, there's a bug in the compiler ( > ERROR: This is a compiler bug. > Please report it via https://issues.dlang.org/enter_bug.cgi ). And in some way there is. The compiler cannot know that the range is infinite, but it can just abort at some point.
Comment #1 by qs.il.paperinik — 2023-09-12T13:35:24Z
I’d suggest DMD abort when a `static foreach` surpasses 2^16−1 (65,535) iterations; also add a compiler switch (suggestion: `-static-foreach-depth=<number>`) to change the aforementioned default for the rare cases it’s needed. Alternatively, a `pragma` could work well, too.
Comment #2 by robert.schadek — 2024-12-13T19:09:03Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/19716 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB