Thread overview
[Issue 12820] DMD can inline calls to functions that use alloca, allocating the memory in the caller function instead.
Jun 02, 2014
Orvid King
Jul 24, 2014
yebblies
Jul 24, 2014
yebblies
Jul 25, 2014
Walter Bright
June 02, 2014
https://issues.dlang.org/show_bug.cgi?id=12820

--- Comment #1 from Orvid King <blah38621@gmail.com> ---
I believe that the issue here is not that DMD inlines alloca (which it should) but instead that it fails to recognize that the memory allocated by alloca should be released at the end of the scope's body.

Another issue that could be considered to fix this exact code is that the alloca call there has a size known at compile-time, and so should actually be getting eliminated entirely in favor of a static array local.

--
July 24, 2014
https://issues.dlang.org/show_bug.cgi?id=12820

yebblies <yebblies@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull
                 CC|                            |yebblies@gmail.com
           Assignee|nobody@puremagic.com        |yebblies@gmail.com

--- Comment #2 from yebblies <yebblies@gmail.com> ---
https://github.com/D-Programming-Language/dmd/pull/3811

--
July 24, 2014
https://issues.dlang.org/show_bug.cgi?id=12820

--- Comment #3 from yebblies <yebblies@gmail.com> ---
(In reply to Orvid King from comment #1)
> I believe that the issue here is not that DMD inlines alloca (which it
> should)
> but instead that it fails to recognize that the memory allocated by alloca
> should be released at the end of the scope's body.

alloca is defined to release memory at the end of the calling function. Releasing memory early would require a different variant of alloca, and while possible, this is difficult.  Since the inliner can't do this conversion, it shouldn't be inlining alloca.

--
July 25, 2014
https://issues.dlang.org/show_bug.cgi?id=12820

Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla@digitalmars.com
            Version|unspecified                 |D2

--
July 25, 2014
https://issues.dlang.org/show_bug.cgi?id=12820

--- Comment #4 from github-bugzilla@puremagic.com ---
Commit pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/292828b19a8ad42a48794292db2646cff6536089
Fix Issue 12820 - DMD can inline calls to functions that use alloca, allocating
the memory in the caller function instead.

--
July 25, 2014
https://issues.dlang.org/show_bug.cgi?id=12820

github-bugzilla@puremagic.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--