[Issue 23099] New: DMD generates dangerous code on array literals usage inside functions

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon May 9 17:23:32 UTC 2022


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: nobody at puremagic.com
          Reporter: contact at lsferreira.net

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;
}

--


More information about the Digitalmars-d-bugs mailing list