diff mbox

[Ada] Minor cleanup in gigi (1/4)

Message ID 1610618.A6zBXvWyLT@polaris
State New
Headers show

Commit Message

Eric Botcazou May 25, 2015, 8:57 p.m. UTC
Tested on x86_64-suse-linux, applied on the mainline.


2015-05-25  Eric Botcazou  <ebotcazou@adacore.com>

	* gcc-interface/decl.c (gnat_to_gnu_entity): Minor tweak.
	* gcc-interface/trans.c (finalize_nrv_unc_r): Use CONSTRUCTOR_ELT.
	* gcc-interface/utils.c (convert): Likewise and simplify.
	(remove_conversions): Likewise.
	* gcc-interface/utils2.c (compare_fat_pointers): Likewise.
	(build_unary_op): Likewise and simplify.
diff mbox

Patch

Index: gcc-interface/utils.c
===================================================================
--- gcc-interface/utils.c	(revision 223644)
+++ gcc-interface/utils.c	(working copy)
@@ -4067,10 +4067,8 @@  convert (tree type, tree expr)
 
       /* If we have just converted to this padded type, just get the
 	 inner expression.  */
-      if (TREE_CODE (expr) == CONSTRUCTOR
-	  && !vec_safe_is_empty (CONSTRUCTOR_ELTS (expr))
-	  && (*CONSTRUCTOR_ELTS (expr))[0].index == TYPE_FIELDS (etype))
-	unpadded = (*CONSTRUCTOR_ELTS (expr))[0].value;
+      if (TREE_CODE (expr) == CONSTRUCTOR)
+	unpadded = CONSTRUCTOR_ELT (expr, 0)->value;
 
       /* Otherwise, build an explicit component reference.  */
       else
@@ -4632,7 +4630,7 @@  remove_conversions (tree exp, bool true_
 	  && TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE
 	  && TYPE_JUSTIFIED_MODULAR_P (TREE_TYPE (exp)))
 	return
-	  remove_conversions ((*CONSTRUCTOR_ELTS (exp))[0].value, true);
+	  remove_conversions (CONSTRUCTOR_ELT (exp, 0)->value, true);
       break;
 
     case COMPONENT_REF:
Index: gcc-interface/decl.c
===================================================================
--- gcc-interface/decl.c	(revision 223652)
+++ gcc-interface/decl.c	(working copy)
@@ -1335,8 +1335,8 @@  gnat_to_gnu_entity (Entity_Id gnat_entit
 		      = TREE_TYPE (DECL_CHAIN (TYPE_FIELDS (gnu_alloc_type)));
 
 		    if (TREE_CODE (gnu_expr) == CONSTRUCTOR
-			&& 1 == vec_safe_length (CONSTRUCTOR_ELTS (gnu_expr)))
-		      gnu_expr = 0;
+			&& vec_safe_length (CONSTRUCTOR_ELTS (gnu_expr)) == 1)
+		      gnu_expr = NULL_TREE;
 		    else
 		      gnu_expr
 			= build_component_ref
Index: gcc-interface/utils2.c
===================================================================
--- gcc-interface/utils2.c	(revision 223652)
+++ gcc-interface/utils2.c	(working copy)
@@ -461,7 +461,7 @@  compare_fat_pointers (location_t loc, tr
 
   /* The constant folder doesn't fold fat pointer types so we do it here.  */
   if (TREE_CODE (p1) == CONSTRUCTOR)
-    p1_array = (*CONSTRUCTOR_ELTS (p1))[0].value;
+    p1_array = CONSTRUCTOR_ELT (p1, 0)->value;
   else
     p1_array = build_component_ref (p1, NULL_TREE,
 				    TYPE_FIELDS (TREE_TYPE (p1)), true);
@@ -472,7 +472,7 @@  compare_fat_pointers (location_t loc, tr
 					 null_pointer_node));
 
   if (TREE_CODE (p2) == CONSTRUCTOR)
-    p2_array = (*CONSTRUCTOR_ELTS (p2))[0].value;
+    p2_array = CONSTRUCTOR_ELT (p2, 0)->value;
   else
     p2_array = build_component_ref (p2, NULL_TREE,
 				    TYPE_FIELDS (TREE_TYPE (p2)), true);
@@ -493,14 +493,14 @@  compare_fat_pointers (location_t loc, tr
     = fold_build2_loc (loc, EQ_EXPR, result_type, p1_array, p2_array);
 
   if (TREE_CODE (p1) == CONSTRUCTOR)
-    p1_bounds = (*CONSTRUCTOR_ELTS (p1))[1].value;
+    p1_bounds = CONSTRUCTOR_ELT (p1, 1)->value;
   else
     p1_bounds
       = build_component_ref (p1, NULL_TREE,
 			     DECL_CHAIN (TYPE_FIELDS (TREE_TYPE (p1))), true);
 
   if (TREE_CODE (p2) == CONSTRUCTOR)
-    p2_bounds = (*CONSTRUCTOR_ELTS (p2))[1].value;
+    p2_bounds = CONSTRUCTOR_ELT (p2, 1)->value;
   else
     p2_bounds
       = build_component_ref (p2, NULL_TREE,
@@ -1445,15 +1445,13 @@  build_unary_op (enum tree_code op_code,
 	      offset = size_binop (PLUS_EXPR, offset,
 				   size_int (bitpos / BITS_PER_UNIT));
 
-	      /* Take the address of INNER, convert the offset to void *, and
-		 add then.  It will later be converted to the desired result
-		 type, if any.  */
-	      inner = build_unary_op (ADDR_EXPR, NULL_TREE, inner);
-	      inner = convert (ptr_void_type_node, inner);
-	      result = build_binary_op (POINTER_PLUS_EXPR, ptr_void_type_node,
+	      /* Take the address of INNER, convert it to a pointer to our type
+		 and add the offset.  */
+	      inner = build_unary_op (ADDR_EXPR,
+				      build_pointer_type (TREE_TYPE (operand)),
+				      inner);
+	      result = build_binary_op (POINTER_PLUS_EXPR, TREE_TYPE (inner),
 					inner, offset);
-	      result = convert (build_pointer_type (TREE_TYPE (operand)),
-				result);
 	      break;
 	    }
 	  goto common;
@@ -1464,12 +1462,12 @@  build_unary_op (enum tree_code op_code,
 	     a pointer to our type.  */
 	  if (TYPE_IS_PADDING_P (type))
 	    {
-	      result = (*CONSTRUCTOR_ELTS (operand))[0].value;
-	      result = convert (build_pointer_type (TREE_TYPE (operand)),
-				build_unary_op (ADDR_EXPR, NULL_TREE, result));
+	      result
+		= build_unary_op (ADDR_EXPR,
+				  build_pointer_type (TREE_TYPE (operand)),
+				  CONSTRUCTOR_ELT (operand, 0)->value);
 	      break;
 	    }
-
 	  goto common;
 
 	case NOP_EXPR:
Index: gcc-interface/trans.c
===================================================================
--- gcc-interface/trans.c	(revision 223652)
+++ gcc-interface/trans.c	(working copy)
@@ -3309,12 +3309,12 @@  finalize_nrv_unc_r (tree *tp, int *walk_
       if (TREE_CODE (ret_val) == COMPOUND_EXPR
 	  && TREE_CODE (TREE_OPERAND (ret_val, 0)) == INIT_EXPR)
 	{
+	  tree rhs = TREE_OPERAND (TREE_OPERAND (ret_val, 0), 1);
+
 	  if (TYPE_IS_FAT_POINTER_P (TREE_TYPE (ret_val)))
-	    ret_val
-	      = (*CONSTRUCTOR_ELTS (TREE_OPERAND (TREE_OPERAND (ret_val, 0),
-						1)))[1].value;
+	    ret_val = CONSTRUCTOR_ELT (rhs, 1)->value;
 	  else
-	    ret_val = TREE_OPERAND (TREE_OPERAND (ret_val, 0), 1);
+	    ret_val = rhs;
 	}
 
       /* Strip useless conversions around the return value.  */
@@ -3365,20 +3365,21 @@  finalize_nrv_unc_r (tree *tp, int *walk_
 
       if (TYPE_IS_FAT_POINTER_P (TREE_TYPE (alloc)))
 	{
+	  tree cst = TREE_OPERAND (alloc, 1);
+
 	  /* The new initial value is a COMPOUND_EXPR with the allocation in
 	     the first arm and the value of P_ARRAY in the second arm.  */
 	  DECL_INITIAL (new_var)
 	    = build2 (COMPOUND_EXPR, TREE_TYPE (new_var),
 		      TREE_OPERAND (alloc, 0),
-		      (*CONSTRUCTOR_ELTS (TREE_OPERAND (alloc, 1)))[0].value);
+		      CONSTRUCTOR_ELT (cst, 0)->value);
 
 	  /* Build a modified CONSTRUCTOR that references NEW_VAR.  */
 	  p_array = TYPE_FIELDS (TREE_TYPE (alloc));
 	  CONSTRUCTOR_APPEND_ELT (v, p_array,
 				  fold_convert (TREE_TYPE (p_array), new_var));
 	  CONSTRUCTOR_APPEND_ELT (v, DECL_CHAIN (p_array),
-				  (*CONSTRUCTOR_ELTS (
-				      TREE_OPERAND (alloc, 1)))[1].value);
+				  CONSTRUCTOR_ELT (cst, 1)->value);
 	  new_ret = build_constructor (TREE_TYPE (alloc), v);
 	}
       else