[Issue 12820] New: DMD can inline calls to functions that use alloca, allocating the memory in the caller function instead.

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Thu May 29 15:15:52 PDT 2014


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: nobody at puremagic.com
          Reporter: opantm2+dbugs at gmail.com

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.

--


More information about the Digitalmars-d-bugs mailing list