This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: tree-inline mishandles ADDR_EXPRs
- From: Alexandre Oliva <aoliva at redhat dot com>
- To: gcc-patches at gcc dot gnu dot org
- Cc: rth at redhat dot com, dnovillo at redhat dot com, jakub at redhat dot com
- Date: 13 Dec 2004 14:59:49 -0200
- Subject: Re: tree-inline mishandles ADDR_EXPRs
- Organization: Red Hat Global Engineering Services Compiler Team
- References: <orfz2dlgcz.fsf@livre.redhat.lsd.ic.unicamp.br>
On Dec 11, 2004, Alexandre Oliva <aoliva@redhat.com> wrote:
> 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?
Here's the simplified patch, that succeeded bootstrap and regression
testing on x86_64-linux-gnu. Ok?
Index: gcc/ChangeLog
from Alexandre Oliva <aoliva@redhat.com>
PR tree-opt/16951
* tree-inline.c (setup_one_parameter): Don't directly map a
parameter to the address of another variable of the same
function.
Index: gcc/tree-inline.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-inline.c,v
retrieving revision 1.156
diff -u -p -r1.156 tree-inline.c
--- gcc/tree-inline.c 9 Dec 2004 10:54:36 -0000 1.156
+++ gcc/tree-inline.c 13 Dec 2004 16:56:13 -0000
@@ -655,6 +655,26 @@ copy_body (inline_data *id)
return body;
}
+/* Return true if VALUE is an ADDR_EXPR of an automatic variable
+ defined in function FN, or of a data member thereof. */
+
+static bool
+self_inlining_addr_expr (tree value, tree fn)
+{
+ tree var;
+
+ if (TREE_CODE (value) != ADDR_EXPR)
+ return false;
+
+ var = get_base_address (TREE_OPERAND (value, 0));
+
+ return var
+ && (TREE_CODE (var) == VAR_DECL
+ || TREE_CODE (var) == PARM_DECL
+ || TREE_CODE (var) == LABEL_DECL)
+ && lang_hooks.tree_inlining.auto_var_in_fn_p (var, fn);
+}
+
static void
setup_one_parameter (inline_data *id, tree p, tree value, tree fn,
tree *init_stmts, tree *vars, bool *gimplify_init_stmts_p)
@@ -679,7 +699,13 @@ setup_one_parameter (inline_data *id, tr
It is not big deal to prohibit constant propagation here as
we will constant propagate in DOM1 pass anyway. */
if (is_gimple_min_invariant (value)
- && lang_hooks.types_compatible_p (TREE_TYPE (value), TREE_TYPE (p)))
+ && lang_hooks.types_compatible_p (TREE_TYPE (value), TREE_TYPE (p))
+ /* We have to be very careful about ADDR_EXPR. Make sure
+ the base variable isn't a local variable of the inlined
+ function, e.g., when doing recursive inlining, direct or
+ mutually-recursive or whatever, which is why we don't
+ just test whether fn == current_function_decl. */
+ && ! self_inlining_addr_expr (value, fn))
{
insert_decl_map (id, p, value);
return;
Index: gcc/testsuite/ChangeLog
from Alexandre Oliva <aoliva@redhat.com>
PR tree-opt/16951
* gcc.c-torture/compile/20041211-1.c: New.
Index: gcc/testsuite/gcc.c-torture/compile/20041211-1.c
===================================================================
RCS file: gcc/testsuite/gcc.c-torture/compile/20041211-1.c
diff -N gcc/testsuite/gcc.c-torture/compile/20041211-1.c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ gcc/testsuite/gcc.c-torture/compile/20041211-1.c 13 Dec 2004 16:56:28 -0000
@@ -0,0 +1,13 @@
+/* PR tree-optimization/16951 */
+
+void dummy_use(const char *p);
+
+__inline void f(const char *const p) {
+ const char q;
+ dummy_use(p);
+ f(&q);
+}
+
+void crash() {
+ f(0);
+}
--
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}