From 39ab2e8fc9d4efb8dc6e089ce69738c2506ec0f1 Mon Sep 17 00:00:00 2001 From: Richard Kenner Date: Tue, 26 Oct 2010 13:06:34 +0000 Subject: utils2.c (build_compound_expr): New function. 2010-10-26 Richard Kenner * 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 --- gcc/ada/ChangeLog | 7 +++++++ gcc/ada/gcc-interface/gigi.h | 5 +++++ gcc/ada/gcc-interface/trans.c | 25 +++++++------------------ gcc/ada/gcc-interface/utils2.c | 27 +++++++++++++++++++++++++++ 4 files changed, 46 insertions(+), 18 deletions(-) (limited to 'gcc/ada') diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index 69ae440..8ff1ac6a 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,10 @@ +2010-10-26 Richard Kenner + + * 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 * sem_prag.adb (Process_Import_Or_Interface): Skip primitives of diff --git a/gcc/ada/gcc-interface/gigi.h b/gcc/ada/gcc-interface/gigi.h index d472239..36966f9 100644 --- a/gcc/ada/gcc-interface/gigi.h +++ b/gcc/ada/gcc-interface/gigi.h @@ -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); diff --git a/gcc/ada/gcc-interface/trans.c b/gcc/ada/gcc-interface/trans.c index 3156e77..f130439 100644 --- a/gcc/ada/gcc-interface/trans.c +++ b/gcc/ada/gcc-interface/trans.c @@ -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: diff --git a/gcc/ada/gcc-interface/utils2.c b/gcc/ada/gcc-interface/utils2.c index 4c0853e..0671308 100644 --- a/gcc/ada/gcc-interface/utils2.c +++ b/gcc/ada/gcc-interface/utils2.c @@ -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. */ -- cgit v1.1