This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: alloca + inline
- From: Xanthakis Stelios <sxanth at ceid dot upatras dot gr>
- To: Robert Dewar <dewar at gnat dot com>
- Cc: gcc at gcc dot gnu dot org, neil at daikokuya dot co dot uk
- Date: Sun, 16 Mar 2003 21:09:00 +0200 (EET)
- Subject: Re: alloca + inline
On Sun, 16 Mar 2003, Robert Dewar wrote:
>
> Certainly I agree that the most natural option is 4), which is that the
> storage should always be reclaimed regardless of whether the function is
> inlined. I agree that it seems a bug if this is not the case, given the
> clear language that describes alloca.
>
Ok, but I think the bug will always exist as long as:
- an inline function is as fast as a macro
and
- always_inline is always obeyed
IMHO, it would be better to make this a gcc extension and
say "This temporary space is automatically freed on return
of the first not-inlined caller".
Then, people will know that they're doing without assumptions.
Those who don't want the effect will either not inline
the function or avoid using alloca. If somebody, now uses
always_inline+alloca in a loop (like the geoffk example)
they're screwed.
So it seems that the right thing is either:
- Make this a gcc extension.
- Reclaim the stack for inlines that call alloca
(and say that an inline is not as fast as a macro
if it calls alloca)
- Forbid inlining and disobey always_inline (and then
add a new always_definatelly_inline attribute:)
Finally, the language that describes alloca is exceptional
anyway: alloca can't be called in function arguments.
alloca is a hack.