utils2.c (build_compound_expr): New function.

2010-10-26  Richard Kenner  <kenner@vlsi1.ultra.nyu.edu>

	* gcc-interface/utils2.c (build_compound_expr): New function.
	* gcc-interface/gigi.h (build_compound_expr): Declare it.
	* gcc-interface/trans.c (Attribute_to_gnu, call_to_gnu): Use it.
	(gnat_to_gnu, case N_Expression_With_Actions): Likewise.

From-SVN: r165958
This commit is contained in:
Richard Kenner 2010-10-26 13:06:34 +00:00 committed by Arnaud Charlet
parent 0592046e23
commit 39ab2e8fc9
4 changed files with 46 additions and 18 deletions

View File

@ -1,3 +1,10 @@
2010-10-26 Richard Kenner <kenner@vlsi1.ultra.nyu.edu>
* gcc-interface/utils2.c (build_compound_expr): New function.
* gcc-interface/gigi.h (build_compound_expr): Declare it.
* gcc-interface/trans.c (Attribute_to_gnu, call_to_gnu): Use it.
(gnat_to_gnu, case N_Expression_With_Actions): Likewise.
2010-10-26 Javier Miranda <miranda@adacore.com>
* sem_prag.adb (Process_Import_Or_Interface): Skip primitives of

View File

@ -777,6 +777,11 @@ extern tree build_unary_op (enum tree_code op_code, tree result_type,
extern tree build_cond_expr (tree result_type, tree condition_operand,
tree true_operand, tree false_operand);
/* Similar, but for COMPOUND_EXPR. */
extern tree build_compound_expr (tree result_type, tree stmt_operand,
tree expr_operand);
/* Similar, but for RETURN_EXPR. */
extern tree build_return_expr (tree ret_obj, tree ret_val);

View File

@ -1955,8 +1955,8 @@ Attribute_to_gnu (Node_Id gnat_node, tree *gnu_result_type_p, int attribute)
example in AARM 11.6(5.e). */
if (prefix_unused && TREE_SIDE_EFFECTS (gnu_prefix)
&& !Is_Entity_Name (Prefix (gnat_node)))
gnu_result = fold_build2 (COMPOUND_EXPR, TREE_TYPE (gnu_result),
gnu_prefix, gnu_result);
gnu_result = build_compound_expr (TREE_TYPE (gnu_result), gnu_prefix,
gnu_result);
*gnu_result_type_p = gnu_result_type;
return gnu_result;
@ -2921,8 +2921,8 @@ call_to_gnu (Node_Id gnat_node, tree *gnu_result_type_p, tree gnu_target)
/* But initialize it on the fly like for an implicit temporary as
we aren't necessarily dealing with a statement. */
gnu_name = build2 (COMPOUND_EXPR, TREE_TYPE (gnu_name), gnu_stmt,
gnu_temp);
gnu_name = build_compound_expr (TREE_TYPE (gnu_name), gnu_stmt,
gnu_temp);
/* Set up to move the copy back to the original if needed. */
if (!in_param)
@ -3307,19 +3307,8 @@ call_to_gnu (Node_Id gnat_node, tree *gnu_result_type_p, tree gnu_target)
/* If we need a value, make a COMPOUND_EXPR to return it; otherwise,
return the result. Deal specially with UNCONSTRAINED_ARRAY_REF. */
if (returning_value)
{
if (TREE_CODE (gnu_call) == UNCONSTRAINED_ARRAY_REF
|| TREE_CODE (gnu_call) == INDIRECT_REF)
gnu_result = build1 (TREE_CODE (gnu_call), TREE_TYPE (gnu_call),
fold_build2 (COMPOUND_EXPR,
TREE_TYPE (TREE_OPERAND (gnu_call,
0)),
gnu_result,
TREE_OPERAND (gnu_call, 0)));
else
gnu_result = fold_build2 (COMPOUND_EXPR, TREE_TYPE (gnu_call),
gnu_result, gnu_call);
}
gnu_result = build_compound_expr (TREE_TYPE (gnu_call), gnu_result,
gnu_call);
return gnu_result;
}
@ -5525,7 +5514,7 @@ gnat_to_gnu (Node_Id gnat_node)
TREE_SIDE_EFFECTS (gnu_result) = 1;
gnu_expr = gnat_to_gnu (Expression (gnat_node));
gnu_result
= build2 (COMPOUND_EXPR, TREE_TYPE (gnu_expr), gnu_result, gnu_expr);
= build_compound_expr (TREE_TYPE (gnu_expr), gnu_result, gnu_expr);
break;
case N_Freeze_Entity:

View File

@ -1372,6 +1372,33 @@ build_cond_expr (tree result_type, tree condition_operand,
return result;
}
/* Similar, but for COMPOUND_EXPR. */
tree
build_compound_expr (tree result_type, tree stmt_operand, tree expr_operand)
{
bool addr_p = false;
tree result;
/* If the result type is unconstrained, take the address of the operand and
then dereference the result. Likewise if the result type is passed by
reference, but this is natively handled in the gimplifier. */
if (TREE_CODE (result_type) == UNCONSTRAINED_ARRAY_TYPE
|| CONTAINS_PLACEHOLDER_P (TYPE_SIZE (result_type)))
{
result_type = build_pointer_type (result_type);
expr_operand = build_unary_op (ADDR_EXPR, result_type, expr_operand);
addr_p = true;
}
result = fold_build2 (COMPOUND_EXPR, result_type, stmt_operand,
expr_operand);
if (addr_p)
result = build_unary_op (INDIRECT_REF, NULL_TREE, result);
return result;
}
/* Similar, but for RETURN_EXPR. If RET_VAL is non-null, build a RETURN_EXPR
around the assignment of RET_VAL to RET_OBJ. Otherwise just build a bare
RETURN_EXPR around RESULT_OBJ, which may be null in this case. */