This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Warn when returning the address of a temporary (middle-end) v2

On Mon, Jun 30, 2014 at 11:37:50PM +0200, Marc Glisse wrote:
> On Mon, 30 Jun 2014, Jeff Law wrote:
> >On 06/29/14 03:22, Marc Glisse wrote:
> >>
> >>After looking at PR 61597, I updated the 2 conditions to:
> >>
> >>+          if ((TREE_CODE (valbase) == VAR_DECL
> >>+               && !is_global_var (valbase))
> >>+              || TREE_CODE (valbase) == PARM_DECL)
> >>
> >>a PARM_DECL is a local variable and returning its address is wrong,
> >>isn't it?
> >Right.  It can live in either a caller or callee allocated slot.
> The "caller" case scares me a bit. Is it really wrong to return the
> address in that case? The slot still exists after returning if the
> caller is responsible for it.

At least on powerpc64, which uses a caller allocated parameter save
area, returning the address of something in the parameter save area
merits a warning.  The ABIs explicitly state that the parameter save
area is not preserved over function calls.

Also note that anything left in a caller allocated parameter save area
will potentially be trashed by arguments written for the next call.

Alan Modra
Australia Development Lab, IBM

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]