On Sun, Jun 19, 2011 at 22:03, Andy Wingo <wi...@pobox.com> wrote: > Hi, > > On Sat 18 Jun 2011 22:25, "Andrew W. Nosenko" <andrew.w.nose...@gmail.com> > writes: > >> On Fri, Jun 17, 2011 at 13:21, Andy Wingo <wi...@pobox.com> wrote: >>> wingo@badger:/tmp$ cat foo.c >>> int >>> find_stack_direction () >>> { >>> static char *addr = 0; >> >> Try to rewrite this line as >> volatile static char *addr = 0; >> It should help. > > It didn't, unfortunately.
You are right. I marked the underlying char as volatile instead of the pointer itself. The proper version seems static char* volatile addr; but ATM I have no compiler around for verify that. Hope, in 3-4 hours I will have ability to verify my guess and have proper verified results. > This issue can be reproduced on a stock Debian unstable system with > gcc-4.6, btw. > >>> I don't know what allows GCC to do this inlining. Could it be a GCC >>> bug? Every time I think I have a GCC bug I'm wrong, though :) >> >> No. It indeed traceable. Just start from main() and you will have >> full trace even with pen and paper. > > Apologies for the ignorant question, but what does "trace" mean? :) "Trace" means that you may "a priory" trace/predict the whole control flow without actual running the code. Therefore, highly optimizing compiler may reduce whole function call to the simple constant. From your description, Gcc occur smart enough for remove the recursion but not enough for simplify to the simple constant. -- Andrew W. Nosenko <andrew.w.nose...@gmail.com>