On Thu, Jun 21, 2012 at 2:21 AM, Richard Guenther <richard.guent...@gmail.com> wrote: > On Thu, Jun 21, 2012 at 7:28 AM, Xinliang David Li <davi...@google.com> wrote: >> I modified the documentation and it now looks like this: >> >> @item -ftemp-stack-reuse >> @opindex ftemp_stack_reuse >> This option enables stack space reuse for temporaries. The default is on. >> The lifetime of a compiler generated temporary is well defined by the C++ >> standard. When a lifetime of a temporary ends, and if the temporary lives >> in memory, an optimizing compiler has the freedom to reuse its stack >> space with other temporaries or scoped local variables whose live range >> does not overlap with it. However some of the legacy code relies on >> the behavior of older compilers in which temporaries' stack space is >> not reused, the aggressive stack reuse can lead to runtime errors. This >> option is used to control the temporary stack reuse optimization. >> >> Does it look ok? > > The flag is not restricted to the C++ compiler and applies to all automatic > variables. The description is very much C++ specific though - I think > it should mention the concept of scopes. > > Also even with this flag there is no guarantee we cannot figure out lifetime > in other ways, for example if the temporary gets promoted to a register.
That should not be an issue then -- if the compiler can figure out the live range via data flow analysis (instead of relying on assertions/markers), the stack reuse or register promotion based on that should always be safe (assuming no bugs in the analysis). > Also with this patch you remove code motion barriers which might cause > other issues. What other issues? It enables more potential code motion, but on the other hand, causes more conservative stack reuse. As far I can tell, the handling of temporaries is added independently after the clobber for scoped variables are introduced. This option can be used to restore the older behavior (in handling temps). thanks, David > > A more "proper" place to fix this is when we actually do the stack reuse, > in cfgexpand. > > So no, I don't think the patch is ok as-is. > > Thanks, > Richard. > >> thanks, >> >> David >> >> On Wed, Jun 20, 2012 at 5:29 PM, Jason Merrill <ja...@redhat.com> wrote: >>> The documentation needs to explain more what the option controls, and why >>> you might want it on or off. Other than that it looks fine. >>> >>> Jason