Bug 23099 – DMD generates dangerous code on array literals usage inside functions

Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2022-05-09T17:23:32Z
Last change time
2024-12-13T19:22:42Z
Assigned to
No Owner
Creator
Luís Ferreira
Moved to GitHub: dmd#20100 →

Comments

Comment #0 by contact — 2022-05-09T17:23:32Z
Currently, DMD clutters the stack when a non-constant literal is used but never modified. For huge literal arrays, this ends up with a stack overflow. The solution here would be to allocate space on the read-only section and point to that when used. --- import core.stdc.stdio; struct S { int[10000000] _; } int main() @nogc { foreach(f; [S()]) printf("%d\n", f._[0]); return 0; }
Comment #1 by maxhaton — 2022-05-10T01:49:07Z
This has probably been filed before. Can't be bothered to go looking at the moment.
Comment #2 by contact — 2022-05-10T01:58:47Z
(In reply to mhh from comment #1) > This has probably been filed before. Can't be bothered to go looking at the > moment. The only issue I found was https://issues.dlang.org/show_bug.cgi?id=14451 but it is not entirely correlated. static foreach can yield stack variables intentionally. For normal foreach the situation is somewhat different. I expect a static foreach to produce stack space, although could be enhanced. Maybe it is not "critical", but above "normal" importance. Somewhat related to https://issues.dlang.org/show_bug.cgi?id=13381 .
Comment #3 by robert.schadek — 2024-12-13T19:22:42Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/20100 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB