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?
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; }