www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 12820] New: DMD can inline calls to functions that use


          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 puremagic.com
          Reporter: opantm2+dbugs 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];

void main() {
        foreach(i; 0 .. 10_000_000) {

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

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

This problem does not occur in GDC.

May 29 2014