https://issues.dlang.org/show_bug.cgi?id=12820

          Issue ID: 12820
           Summary: DMD can inline calls to functions that use alloca,
                    allocating the memory in the caller function instead.
           Product: D
           Version: unspecified
          Hardware: All
                OS: All
            Status: NEW
          Keywords: wrong-code
          Severity: major
          Priority: P1
         Component: DMD
          Assignee: [email protected]
          Reporter: [email protected]

Functions that use 'alloca' shouldn't be allowed to be inlined because then
memory is allocated in the stack of the caller function. This causes memory to
not be freed when expected. Example:

import core.stdc.stdlib, std.conv, std.stdio;

class C { }

void foo() {
        enum size = __traits(classInstanceSize, C);
        void[] mem = alloca(size)[0..size];
        emplace!C(mem);
}

void main() {
        foreach(i; 0 .. 10_000_000) {
                foo();
        }
        writeln("Done!");
}


With -inline:
rdmd -O -release -inline test2.d
Segmentation fault

Without -inline:
rdmd -O -release test2.d
Done!


This problem does not occur in GDC.

--

Reply via email to