Hi,

On Thu, 13 Jun 2019, Jeff Law wrote:

> > (In fact I think our builtin_alloca implementation could benefit when we 
> > added that behaviour as well; it's a natural wish to be able to free 
> > memory that you allocated).
> 
> Also note that simply sprinkling alloca(0) calls won't magically release
> memory.  In a stack implementation releasing happens when the frame is
> removed.  Doing something more complex than that seems unwise.

Yeah, on reconsideration I think I'm pedaling back on this suggestion 
(which really was to do something more complex).  We have the necessary 
support for this in GCC (for VLAs), and then we'd be able to support code 
like this:

  for () {
    dostuff (alloca (size));
    morestuff (alloca (size2));
    alloca(0);   // free all allocas
  }

without running the risk of unlimited stack use.  But of course this would 
promote a programming style that'd only work with our alloca (and not even 
C-alloca), and we want to avoid that.  I thought it a cute idea, but was 
carried away by the cuteness ;-)

I like the suggestion of setting (and carrying through the pipeline) the 
TREE_NO_WARNING flag on an source 'alloca(0)'.


Ciao,
Michael.

Reply via email to