https://issues.dlang.org/show_bug.cgi?id=23099
Issue ID: 23099
Summary: DMD generates dangerous code on array literals usage
inside functions
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: critical
Priority: P1
Component: dmd
Assignee: [email protected]
Reporter: [email protected]
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;
}
--