This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: tail calls in const functions?
> On Thu, Mar 23, 2000 at 03:24:31PM +0100, Jan Hubicka wrote:
> > Hi
> > The tail call optimization makes function to modify the stack, that
> > belongs to the caller. Is this valid for const function?
> > IMO gcc has right to optimize out:
> > int test()
> > {
> > return c(1) + d(1);
> > }
> > the second store of 1, in case c is const function (it don't do that currently).
>
> This is actually a wrong example, because none of these functions can be
> a tail call (the parent routine has to sum the two returned values up).
The problem is not in function test, but in the function c.
Imagine function c like this one:
int
__attribute__ ((const))
c(int a)
{
return e(a+1);
}
The c (after tail-call optimizations done) will clobber the stack
created by function test.
Honza
>
> Cheers,
> Jakub
> ___________________________________________________________________
> Jakub Jelinek | jakub@redhat.com | http://sunsite.mff.cuni.cz/~jj
> Linux version 2.3.99-pre2 on a sparc64 machine (1343.49 BogoMips)
> ___________________________________________________________________