Commit 39ab2e8f by Richard Kenner Committed by Arnaud Charlet

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
parent 0592046e
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
......
......@@ -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);
......
......@@ -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,7 +2921,7 @@ 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_name = build_compound_expr (TREE_TYPE (gnu_name), gnu_stmt,
gnu_temp);
/* Set up to move the copy back to the original if needed. */
......@@ -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:
......
......@@ -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. */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment