This is the mail archive of the gcc-patches@gcc.gnu.org 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 06/30/14 15:37, 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.
The slot exists, but its contents are undefined. The caller never even knows if the callee ever flushed an object back to those slots or if it did flush back, which objects were flushed and in what state.

There was a time when I was pondering using those slots for saving callee saved registers on the PA so that leafs that needed a few stack slots wouldn't need to allococate a new frame, instead it'd just use those convenient 4 words. But this turned out to just not be important and it would totally hose the unwinding mechanisms that were in use on the PA at the time.

Jeff


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