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]

[Patch] Fix 17483, ICE with NRV and taking its address


I don't know if this is the right place to fix this but it does pass
the testsuite and also fixes the testcase in the bug report.
Basically we were not marking the variable as TREE_ADDRESSABLE
even though we taking the address of the variable.  The reason why
we did not is because we did NRV in the C++ front-end and then
we replace the RETURN_DECL with the DECL and the new DECL does not
get marked with TREE_ADDRESSABLE which causes the ICE.

OK? Bootstraped on powerpc-apple-darwin with no regressions.

Note the testcase does not ICE on i686-*-* because we don't do
NRV until after doing the inlining.

Thanks,
Andrew Pinski

Testcase:
// { dg-options "-O3" }
struct A { int i; };
struct A foo()
{
    struct A a;
    int *aaa = &a.i;
    *aaa = 0;
    return a;
}
void bar()
{
    foo();
}

ChangeLog:

	* tree-inline.c (copy_body_r): When we are copying into
	an address expression, make sure that we mark the decl
	if any is TREE_ADDRESSABLE.

Patch:
Index: tree-inline.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-inline.c,v
retrieving revision 1.140
diff -u -p -r1.140 tree-inline.c
--- tree-inline.c	13 Sep 2004 02:28:19 -0000	1.140
+++ tree-inline.c	16 Sep 2004 02:03:06 -0000
@@ -625,8 +625,19 @@ copy_body_r (tree *tp, int *walk_subtree
 	 and friends are up-to-date.  */
       else if (TREE_CODE (*tp) == ADDR_EXPR)
 	{
+	  tree base;
 	  walk_tree (&TREE_OPERAND (*tp, 0), copy_body_r, id, NULL);
 	  recompute_tree_invarant_for_addr_expr (*tp);
+	  base = TREE_OPERAND (*tp, 0);
+
+	  /* Also mark the variable as tree-addressable. */
+          while (handled_component_p (base)
+		 || TREE_CODE (base) == REALPART_EXPR
+		 || TREE_CODE (base) == IMAGPART_EXPR)
+	    base = TREE_OPERAND (base, 0);
+	  if (DECL_P (base))
+	    TREE_ADDRESSABLE (base) = 1;
+
 	  *walk_subtrees = 0;
 	}
     }


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