diff mbox

[Ada] Fix ICE on array with unaligned index type at -O3

Message ID 45708284.trDWrk8Xlv@polaris
State New
Headers show

Commit Message

Eric Botcazou Nov. 24, 2014, 8:15 a.m. UTC
This is a regression present on the mainline and 4.9 branch involving an array 
with an unaligned index type and when -O3 is specified.

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


2014-11-24  Eric Botcazou  <ebotcazou@adacore.com>

	* gcc-interface/trans.c (push_range_check_info): Replace early test
	with assertion.
	(Raise_Error_to_gnu): Do not call push_range_check_info if the loop
	stack is empty.
	* gcc-interface/utils.c (convert_to_fat_pointer): Fix formatting.
	* gcc-interface/utils2.c (gnat_invariant_expr): Deal with padded types
	and revert latest change.


2014-11-24  Eric Botcazou  <ebotcazou@adacore.com>

	* gnat.dg/opt45.adb: New test.
diff mbox

Patch

Index: gcc-interface/utils.c
===================================================================
--- gcc-interface/utils.c	(revision 217961)
+++ gcc-interface/utils.c	(working copy)
@@ -3860,8 +3860,7 @@  convert_to_fat_pointer (tree type, tree
 	{
 	  /* The template type can still be dummy at this point so we build an
 	     empty constructor.  The middle-end will fill it in with zeros.  */
-	  t = build_constructor (template_type,
-				 NULL);
+	  t = build_constructor (template_type, NULL);
 	  TREE_CONSTANT (t) = TREE_STATIC (t) = 1;
 	  null_bounds = build_unary_op (ADDR_EXPR, NULL_TREE, t);
 	  SET_TYPE_NULL_BOUNDS (ptr_template_type, null_bounds);
Index: gcc-interface/utils2.c
===================================================================
--- gcc-interface/utils2.c	(revision 217961)
+++ gcc-interface/utils2.c	(working copy)
@@ -2780,7 +2780,13 @@  gnat_invariant_expr (tree expr)
 	  || (TREE_CODE (expr) == VAR_DECL && TREE_READONLY (expr)))
 	 && decl_function_context (expr) == current_function_decl
 	 && DECL_INITIAL (expr))
-    expr = remove_conversions (DECL_INITIAL (expr), false);
+    {
+      expr = DECL_INITIAL (expr);
+      /* Look into CONSTRUCTORs built to initialize padded types.  */
+      if (TYPE_IS_PADDING_P (TREE_TYPE (expr)))
+	expr = convert (TREE_TYPE (TYPE_FIELDS (TREE_TYPE (expr))), expr);
+      expr = remove_conversions (expr, false);
+    }
 
   if (TREE_CONSTANT (expr))
     return fold_convert (type, expr);
@@ -2836,7 +2842,7 @@  object:
   if (!TREE_READONLY (t))
     return NULL_TREE;
 
-  if (TREE_CODE (t) == CONSTRUCTOR || TREE_CODE (t) == PARM_DECL)
+  if (TREE_CODE (t) == PARM_DECL)
     return fold_convert (type, expr);
 
   if (TREE_CODE (t) == VAR_DECL
Index: gcc-interface/trans.c
===================================================================
--- gcc-interface/trans.c	(revision 217965)
+++ gcc-interface/trans.c	(working copy)
@@ -2569,9 +2569,6 @@  push_range_check_info (tree var)
   struct loop_info_d *iter = NULL;
   unsigned int i;
 
-  if (vec_safe_is_empty (gnu_loop_stack))
-    return NULL;
-
   var = remove_conversions (var, false);
 
   if (TREE_CODE (var) != VAR_DECL)
@@ -2580,6 +2577,8 @@  push_range_check_info (tree var)
   if (decl_function_context (var) != current_function_decl)
     return NULL;
 
+  gcc_assert (vec_safe_length (gnu_loop_stack) > 0);
+
   for (i = vec_safe_length (gnu_loop_stack) - 1;
        vec_safe_iterate (gnu_loop_stack, i, &iter);
        i--)
@@ -5175,6 +5174,7 @@  Raise_Error_to_gnu (Node_Id gnat_node, t
 	     the original checks reinstated, and a run time selection.
 	     The former loop will be suitable for vectorization.  */
 	  if (flag_unswitch_loops
+	      && !vec_safe_is_empty (gnu_loop_stack)
 	      && (!gnu_low_bound
 		  || (gnu_low_bound = gnat_invariant_expr (gnu_low_bound)))
 	      && (!gnu_high_bound