diff mbox

[Ada] Fix ICE on double renaming with chain of access types

Message ID 2936922.FcVY0T6Fgs@polaris
State New
Headers show

Commit Message

Eric Botcazou Nov. 13, 2016, 6:13 p.m. UTC
This is a regression present on the mainline and 6 branch: the compiler ICEs 
in the gimplifier on a double renaming with a chain of access types because 
there is a orphaned PLACEHOLDER_EXPR.

Tested on x86_64-suse-linux, applied on the mainline and 6 branch.


2016-11-13  Eric Botcazou  <ebotcazou@adacore.com>

	* gcc-interface/utils2.c (gnat_protect_expr): Also protect only the
	address if the expression is the component of a dereference.
	Do not use a reference type for the final temporary reference.


2016-11-13  Eric Botcazou  <ebotcazou@adacore.com>

	* gnat.dg/renaming11.ad[sb]: New test.

-- 
Eric Botcazou
diff mbox

Patch

Index: gcc-interface/utils2.c
===================================================================
--- gcc-interface/utils2.c	(revision 242334)
+++ gcc-interface/utils2.c	(working copy)
@@ -2586,6 +2586,12 @@  gnat_protect_expr (tree exp)
       return t;
     }
 
+  /* Likewise if we're indirectly referencing part of something.  */
+  if (code == COMPONENT_REF
+      && TREE_CODE (TREE_OPERAND (exp, 0)) == INDIRECT_REF)
+    return build3 (code, type, gnat_protect_expr (TREE_OPERAND (exp, 0)),
+		   TREE_OPERAND (exp, 1), NULL_TREE);
+
   /* If this is a COMPONENT_REF of a fat pointer, save the entire fat pointer.
      This may be more efficient, but will also allow us to more easily find
      the match for the PLACEHOLDER_EXPR.  */
@@ -2605,9 +2611,7 @@  gnat_protect_expr (tree exp)
   /* Otherwise reference, protect the address and dereference.  */
   return
     build_unary_op (INDIRECT_REF, type,
-		    save_expr (build_unary_op (ADDR_EXPR,
-					       build_reference_type (type),
-					       exp)));
+		    save_expr (build_unary_op (ADDR_EXPR, NULL_TREE, exp)));
 }
 
 /* This is equivalent to stabilize_reference_1 in tree.c but we take an extra