diff options
author | Eric Botcazou <ebotcazou@adacore.com> | 2011-09-11 19:14:51 +0000 |
---|---|---|
committer | Eric Botcazou <ebotcazou@gcc.gnu.org> | 2011-09-11 19:14:51 +0000 |
commit | 7e169899559dd04cbde3bf6e0599720e6918a461 (patch) | |
tree | f19f0298aa8dad59a5d734a4bb0796ab0a2169e7 /gcc | |
parent | 819a653eee396dc4db95ddc3c87805acab08c2de (diff) | |
download | gcc-7e169899559dd04cbde3bf6e0599720e6918a461.zip gcc-7e169899559dd04cbde3bf6e0599720e6918a461.tar.gz gcc-7e169899559dd04cbde3bf6e0599720e6918a461.tar.bz2 |
utils.c (maybe_unconstrained_array): In the reference to unconstrained array case, deal with each branch of a COND_EXPR.
* gcc-interface/utils.c (maybe_unconstrained_array): In the reference
to unconstrained array case, deal with each branch of a COND_EXPR.
* gcc-interface/utils2.c (build_allocator): Deal with each branch of
a COND_EXPR in the initializer, if present.
From-SVN: r178766
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ada/ChangeLog | 7 | ||||
-rw-r--r-- | gcc/ada/gcc-interface/utils.c | 45 | ||||
-rw-r--r-- | gcc/ada/gcc-interface/utils2.c | 10 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 4 | ||||
-rw-r--r-- | gcc/testsuite/gnat.dg/cond_expr2.adb | 11 | ||||
-rw-r--r-- | gcc/testsuite/gnat.dg/cond_expr2.ads | 5 |
6 files changed, 71 insertions, 11 deletions
diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index d909529..fd84feb 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,5 +1,12 @@ 2011-09-11 Eric Botcazou <ebotcazou@adacore.com> + * gcc-interface/utils.c (maybe_unconstrained_array): In the reference + to unconstrained array case, deal with each branch of a COND_EXPR. + * gcc-interface/utils2.c (build_allocator): Deal with each branch of + a COND_EXPR in the initializer, if present. + +2011-09-11 Eric Botcazou <ebotcazou@adacore.com> + * gcc-interface/decl.c (maybe_pad_type): Do not try to change the form of an addressable type. * gcc-interface/trans.c (gnat_gimplify_expr) <VIEW_CONVERT_EXPR>: New. diff --git a/gcc/ada/gcc-interface/utils.c b/gcc/ada/gcc-interface/utils.c index 1a10347..0176c3e 100644 --- a/gcc/ada/gcc-interface/utils.c +++ b/gcc/ada/gcc-interface/utils.c @@ -4241,22 +4241,44 @@ tree maybe_unconstrained_array (tree exp) { enum tree_code code = TREE_CODE (exp); - tree new_exp; switch (TREE_CODE (TREE_TYPE (exp))) { case UNCONSTRAINED_ARRAY_TYPE: if (code == UNCONSTRAINED_ARRAY_REF) { - new_exp = TREE_OPERAND (exp, 0); - new_exp - = build_unary_op (INDIRECT_REF, NULL_TREE, - build_component_ref (new_exp, NULL_TREE, - TYPE_FIELDS - (TREE_TYPE (new_exp)), - false)); - TREE_READONLY (new_exp) = TREE_READONLY (exp); - return new_exp; + const bool read_only = TREE_READONLY (exp); + exp = TREE_OPERAND (exp, 0); + if (TREE_CODE (exp) == COND_EXPR) + { + tree op1 + = build_unary_op (INDIRECT_REF, NULL_TREE, + build_component_ref (TREE_OPERAND (exp, 1), + NULL_TREE, + TYPE_FIELDS + (TREE_TYPE (exp)), + false)); + tree op2 + = build_unary_op (INDIRECT_REF, NULL_TREE, + build_component_ref (TREE_OPERAND (exp, 2), + NULL_TREE, + TYPE_FIELDS + (TREE_TYPE (exp)), + false)); + + exp = build3 (COND_EXPR, + TREE_TYPE (TREE_TYPE (TYPE_FIELDS + (TREE_TYPE (exp)))), + TREE_OPERAND (exp, 0), op1, op2); + } + else + exp = build_unary_op (INDIRECT_REF, NULL_TREE, + build_component_ref (exp, NULL_TREE, + TYPE_FIELDS + (TREE_TYPE (exp)), + false)); + TREE_READONLY (exp) = read_only; + return exp; } else if (code == NULL_EXPR) @@ -4270,7 +4292,8 @@ maybe_unconstrained_array (tree exp) it contains a template. */ if (TYPE_PADDING_P (TREE_TYPE (exp))) { - new_exp = convert (TREE_TYPE (TYPE_FIELDS (TREE_TYPE (exp))), exp); + tree new_exp + = convert (TREE_TYPE (TYPE_FIELDS (TREE_TYPE (exp))), exp); if (TREE_CODE (TREE_TYPE (new_exp)) == RECORD_TYPE && TYPE_CONTAINS_TEMPLATE_P (TREE_TYPE (new_exp))) return diff --git a/gcc/ada/gcc-interface/utils2.c b/gcc/ada/gcc-interface/utils2.c index 424a0c0..87cb269 100644 --- a/gcc/ada/gcc-interface/utils2.c +++ b/gcc/ada/gcc-interface/utils2.c @@ -2046,6 +2046,16 @@ build_allocator (tree type, tree init, tree result_type, Entity_Id gnat_proc, if (init && TREE_CODE (init) == NULL_EXPR) return build1 (NULL_EXPR, result_type, TREE_OPERAND (init, 0)); + /* If the initializer, if present, is a COND_EXPR, deal with each branch. */ + else if (init && TREE_CODE (init) == COND_EXPR) + return build3 (COND_EXPR, result_type, TREE_OPERAND (init, 0), + build_allocator (type, TREE_OPERAND (init, 1), result_type, + gnat_proc, gnat_pool, gnat_node, + ignore_init_type), + build_allocator (type, TREE_OPERAND (init, 2), result_type, + gnat_proc, gnat_pool, gnat_node, + ignore_init_type)); + /* If RESULT_TYPE is a fat or thin pointer, set SIZE to be the sum of the sizes of the object and its template. Allocate the whole thing and fill in the parts that are known. */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 1a298b1..3544a27 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,9 @@ 2011-09-11 Eric Botcazou <ebotcazou@adacore.com> + * gnat.dg/cond_expr2.ad[sb]: New test. + +2011-09-11 Eric Botcazou <ebotcazou@adacore.com> + * gnat.dg/atomic5.ad[sb]: New test. 2011-09-10 H.J. Lu <hongjiu.lu@intel.com> diff --git a/gcc/testsuite/gnat.dg/cond_expr2.adb b/gcc/testsuite/gnat.dg/cond_expr2.adb new file mode 100644 index 0000000..02e3ee3 --- /dev/null +++ b/gcc/testsuite/gnat.dg/cond_expr2.adb @@ -0,0 +1,11 @@ +-- { dg-do compile } +-- { dg-options "-gnat12" } + +package body Cond_Expr2 is + + function F (X : integer) return String is + begin + return (if X > 0 then "positive" else "negative"); + end; + +end Cond_Expr2; diff --git a/gcc/testsuite/gnat.dg/cond_expr2.ads b/gcc/testsuite/gnat.dg/cond_expr2.ads new file mode 100644 index 0000000..11c8229 --- /dev/null +++ b/gcc/testsuite/gnat.dg/cond_expr2.ads @@ -0,0 +1,5 @@ +package Cond_Expr2 is + + function F (X : integer) return String; + +end Cond_Expr2; |