aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada/gcc-interface/decl.c
diff options
context:
space:
mode:
authorEric Botcazou <ebotcazou@adacore.com>2014-10-27 10:56:04 +0000
committerEric Botcazou <ebotcazou@gcc.gnu.org>2014-10-27 10:56:04 +0000
commit33ccc5363ec5994c39048b1aa18e6ae6e35aa2a9 (patch)
tree89f9bc56de9dc2fbc474b2c63f3ed7f470ca3868 /gcc/ada/gcc-interface/decl.c
parent0a2e22ec88620328fe7511e75536b942cf672a7a (diff)
downloadgcc-33ccc5363ec5994c39048b1aa18e6ae6e35aa2a9.zip
gcc-33ccc5363ec5994c39048b1aa18e6ae6e35aa2a9.tar.gz
gcc-33ccc5363ec5994c39048b1aa18e6ae6e35aa2a9.tar.bz2
decl.c (gnat_to_gnu_entity): Remove superfluous computation for the max size.
* gcc-interface/decl.c (gnat_to_gnu_entity) <E_Array_Type>: Remove superfluous computation for the max size. <E_Array_Subtype>: Likewise. Make sure that the max size calculation does not overflow at compile time. From-SVN: r216725
Diffstat (limited to 'gcc/ada/gcc-interface/decl.c')
-rw-r--r--gcc/ada/gcc-interface/decl.c37
1 files changed, 20 insertions, 17 deletions
diff --git a/gcc/ada/gcc-interface/decl.c b/gcc/ada/gcc-interface/decl.c
index b68870d..97fd3b5 100644
--- a/gcc/ada/gcc-interface/decl.c
+++ b/gcc/ada/gcc-interface/decl.c
@@ -2127,11 +2127,8 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, int definition)
tree gnu_max
= convert (sizetype, TYPE_MAX_VALUE (gnu_index_type));
tree gnu_this_max
- = size_binop (MAX_EXPR,
- size_binop (PLUS_EXPR, size_one_node,
- size_binop (MINUS_EXPR,
- gnu_max, gnu_min)),
- size_zero_node);
+ = size_binop (PLUS_EXPR, size_one_node,
+ size_binop (MINUS_EXPR, gnu_max, gnu_min));
if (TREE_CODE (gnu_this_max) == INTEGER_CST
&& TREE_OVERFLOW (gnu_this_max))
@@ -2464,20 +2461,26 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, int definition)
gnu_max_size = NULL_TREE;
else
{
- tree gnu_this_max
- = size_binop (MAX_EXPR,
- size_binop (PLUS_EXPR, size_one_node,
- size_binop (MINUS_EXPR,
+ tree gnu_this_max;
+
+ /* Use int_const_binop if the bounds are constant to
+ avoid any unwanted overflow. */
+ if (TREE_CODE (gnu_base_min) == INTEGER_CST
+ && TREE_CODE (gnu_base_max) == INTEGER_CST)
+ gnu_this_max
+ = int_const_binop (PLUS_EXPR, size_one_node,
+ int_const_binop (MINUS_EXPR,
gnu_base_max,
- gnu_base_min)),
- size_zero_node);
-
- if (TREE_CODE (gnu_this_max) == INTEGER_CST
- && TREE_OVERFLOW (gnu_this_max))
- gnu_max_size = NULL_TREE;
+ gnu_base_min));
else
- gnu_max_size
- = size_binop (MULT_EXPR, gnu_max_size, gnu_this_max);
+ gnu_this_max
+ = size_binop (PLUS_EXPR, size_one_node,
+ size_binop (MINUS_EXPR,
+ gnu_base_max,
+ gnu_base_min));
+
+ gnu_max_size
+ = size_binop (MULT_EXPR, gnu_max_size, gnu_this_max);
}
}