This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: optimize malloc to stack allocation.
On Wed, Jan 09, 2013 at 05:12:06PM +0100, Marc Glisse wrote:
> On Wed, 9 Jan 2013, OndÅej BÃlka wrote:
>
> >gcc currently does not even optimize following fragment:
> >
> >int foo(){
> > char *x=malloc(64);
> > free(x);
> >}
>
> Yes it does.
> (not that more optimizations aren't possible, but it does this one)
Sorry I did checked this only with old gcc. Recent gcc does eliminates
this by DCE which was not point of that example.
This is correct example.
int foo(){
char *x=malloc(64);
x[3]=4;
int z=x[3];
free(x);
return z;
}
>
> --
> Marc Glisse