This is the mail archive of the
mailing list for the GCC project.
Re: Forbid __builtin_return_address when inlining
Andrew Haley wrote:
> Mark Mitchell writes:
> > Andrew Haley wrote:
> > > __builtin_return_address(0) returns the wrong address if its caller
> > > has been inlined. Weirdly, we never seem to have detected this
> > > before, but it surely must be wrong.
> > The manual says:
> > > When
> > > inlining the expected behavior is that the function will return
> > > the address of the function that will be returned to. To work
> > > around this behavior use the `noinline' function attribute.
> > which seems to suggest that the behavior you are seeing as is
> > documented, peculiar though it seems.
> Hmm, OK. But if I fixed the peculiar behavour then I could also
> remove the peculiar documentation, couldn't I? That would surely be
> an improvement.,,
The problem is that we don't know how people may already be using this
"feature". Since someone bothered to document it, I wouldn't be
surprised if something (the Linux kernel? a scripting language
interpreter?) is using it in some way that depends on the current behavior.
So, I fully agree that the semantics you're proposing seem more sensible
(i.e., tell me where *this function* returns, and, if necessary, make
sure that it has somewhere to return to by not inlining it), but I'd be
nervous about making the change. Is there a compelling reason to change
this, other than just that it makes sense?
(650) 331-3385 x713