tree-inline mishandles ADDR_EXPRs

Alexandre Oliva aoliva@redhat.com
Sat Dec 11 03:00:00 GMT 2004


The tree inliner doesn't handle passing addresses of local variables
to inlined functions correctly.

In the case of one function passing the address of a local variable as
an argument to another function, if this latter function happens to be
inlined, if we map the parameter to the ADDR_EXPR (as opposed to
creating a VAR_DECL and assigning the ADDR_EXPR to it), we may end up
mapping the variable within the ADDR_EXPR to another decl, setting it
apart from the variable whose address was actually passed as an
argument.

As far as I can tell, we never do this in normal cases, because
auto_var_in_fn_p doesn't hold for the passed-in variable.  Unless, as
in PR16951, we have a function inlined into itself, and it takes a
pointer to a variable that is automatic in the caller.  In this case,
the predicate holds, so we don't want to apply the direct-binding
optimization, otherwise we wouldn't be able to tell references to the
caller variable from references within the callee.

This patch makes this change, and goes a bit further, in that, if we
apply the optimization (i.e., not in the self-inlining case), we make
sure the base variable of the ADDR_EXPR is mapped to itself.  Now I'm
having second thoughts on whether we actually need this (I hadn't
realized the auto_var_in_fn_p would prevent the remapping before
composing this e-mail).  Maybe all we need is to avoid the
optimization for self-inlining.  It would probably have seemed far
more broken otherwise.

Anyhow, here's the patch that succeeded bootstrapping on
x86_64-linux-gnu.  I'll start bootstrapping and testing a simplified
version now and report back later.  Is this, or the simplified version
(that doesn't do the self-remapping), ok to install?

-------------- next part --------------
A non-text attachment was scrubbed...
Name: tree-inline-remap-addr-expr.patch
Type: text/x-patch
Size: 2084 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20041211/23db7c46/attachment.bin>
-------------- next part --------------

-- 
Alexandre Oliva             http://www.ic.unicamp.br/~oliva/
Red Hat Compiler Engineer   aoliva@{redhat.com, gcc.gnu.org}
Free Software Evangelist  oliva@{lsd.ic.unicamp.br, gnu.org}


More information about the Gcc-patches mailing list