On Sun, Jan 6, 2013 at 1:28 AM, Ye Joey <joey.ye...@gmail.com> wrote:
> In following example, call to sbfoo isn't a tail call with -O2. GCC
> analyzes local variable may be referenced in sbfoo. Is it a reasonable
> analysis? In another word, is it a legal program that bar stores
> address of local to a static variable, and then for sbfoo to access
> it?

Yes since local does not go out of scope until the return of foo which
is after the call to sbfoo.

Thanks,
Andrew Pinski
>
> This issue cause a missed tail call opportunity in newlib, thus
> unnecessarily increased stack consumption.
>
> a.c:
> extern int sbfoo(void);
> extern int bar(int *);
> int foo()
> {
>     int local = 0;
>     if (bar(&local)) return 0;
>
>     return sbfoo();
> }
>
> b.c:
> int * g;
> int bar(int *c) { g=c; return 0;}
>
> int sbfoo() { return *g; }

Reply via email to