aboutsummaryrefslogtreecommitdiff
path: root/gcc/stor-layout.c
diff options
context:
space:
mode:
authorRichard Guenther <rguenther@suse.de>2012-05-02 11:22:31 +0000
committerRichard Biener <rguenth@gcc.gnu.org>2012-05-02 11:22:31 +0000
commit56099f00a526f137d24bbf2ac6def05003ebe5c5 (patch)
tree3260d223788c7f661eef298b55f74eb6033bc7f0 /gcc/stor-layout.c
parent795e8869fd8be77f9221f1b3884b228601f7c7d6 (diff)
downloadgcc-56099f00a526f137d24bbf2ac6def05003ebe5c5.zip
gcc-56099f00a526f137d24bbf2ac6def05003ebe5c5.tar.gz
gcc-56099f00a526f137d24bbf2ac6def05003ebe5c5.tar.bz2
tree.c (valid_constant_size_p): New function.
2012-05-02 Richard Guenther <rguenther@suse.de> * tree.c (valid_constant_size_p): New function. * tree.h (valid_constant_size_p): Declare. * cfgexpand.c (expand_one_var): Adjust check for too large variables by using valid_constant_size_p. * varasm.c (assemble_variable): Likewise. c/ * c-decl.c (grokdeclarator): Properly check for sizes that cover more than half of the address-space. cp/ * decl.c (grokdeclarator): Properly check for sizes that cover more than half of the address-space. 2012-05-02 Richard Guenther <rguenther@suse.de> * fold-const.c (div_if_zero_remainder): sizetypes no longer sign-extend. (int_const_binop_1): New worker for int_const_binop with overflowable parameter. Pass it through to force_fit_type_double. (int_const_binop): Wrap around int_const_binop_1 with overflowable equal to one. (size_binop_loc): Call int_const_binop_1 with overflowable equal to minus one, forcing overflow detection for even unsigned types. (extract_muldiv_1): Remove bogus TYPE_IS_SIZETYPE special-casing. (fold_binary_loc): Call try_move_mult_to_index with signed offset. * stor-layout.c (initialize_sizetypes): sizetypes no longer sign-extend. (layout_type): For zero-sized arrays ignore overflow on the size calculations. * tree-ssa-ccp.c (bit_value_unop_1): Likewise. (bit_value_binop_1): Likewise. * tree.c (double_int_to_tree): Likewise. (double_int_fits_to_tree_p): Likewise. (force_fit_type_double): Likewise. (host_integerp): Likewise. (int_fits_type_p): Likewise. * varasm.c (output_constructor_regular_field): Sign-extend the field-offset to cater for negative offsets produced by the Ada frontend. * omp-low.c (extract_omp_for_data): Convert the loop step to signed for pointer adjustments. * g++.dg/tree-ssa/pr19807.C: Adjust. From-SVN: r187042
Diffstat (limited to 'gcc/stor-layout.c')
-rw-r--r--gcc/stor-layout.c46
1 files changed, 31 insertions, 15 deletions
diff --git a/gcc/stor-layout.c b/gcc/stor-layout.c
index e72e7f3..12a6c13 100644
--- a/gcc/stor-layout.c
+++ b/gcc/stor-layout.c
@@ -2182,11 +2182,37 @@ layout_type (tree type)
that (possible) negative values are handled appropriately
when determining overflow. */
else
- length
- = fold_convert (sizetype,
- size_binop (PLUS_EXPR,
- build_int_cst (TREE_TYPE (lb), 1),
- size_binop (MINUS_EXPR, ub, lb)));
+ {
+ /* ??? When it is obvious that the range is signed
+ represent it using ssizetype. */
+ if (TREE_CODE (lb) == INTEGER_CST
+ && TREE_CODE (ub) == INTEGER_CST
+ && TYPE_UNSIGNED (TREE_TYPE (lb))
+ && tree_int_cst_lt (ub, lb))
+ {
+ lb = double_int_to_tree
+ (ssizetype,
+ double_int_sext (tree_to_double_int (lb),
+ TYPE_PRECISION (TREE_TYPE (lb))));
+ ub = double_int_to_tree
+ (ssizetype,
+ double_int_sext (tree_to_double_int (ub),
+ TYPE_PRECISION (TREE_TYPE (ub))));
+ }
+ length
+ = fold_convert (sizetype,
+ size_binop (PLUS_EXPR,
+ build_int_cst (TREE_TYPE (lb), 1),
+ size_binop (MINUS_EXPR, ub, lb)));
+ }
+
+ /* If we arrived at a length of zero ignore any overflow
+ that occured as part of the calculation. There exists
+ an association of the plus one where that overflow would
+ not happen. */
+ if (integer_zerop (length)
+ && TREE_OVERFLOW (length))
+ length = size_zero_node;
TYPE_SIZE (type) = size_binop (MULT_EXPR, element_size,
fold_convert (bitsizetype,
@@ -2453,11 +2479,6 @@ initialize_sizetypes (void)
TYPE_SIZE_UNIT (sizetype) = size_int (GET_MODE_SIZE (TYPE_MODE (sizetype)));
set_min_and_max_values_for_integral_type (sizetype, precision,
/*is_unsigned=*/true);
- /* sizetype is unsigned but we need to fix TYPE_MAX_VALUE so that it is
- sign-extended in a way consistent with force_fit_type. */
- TYPE_MAX_VALUE (sizetype)
- = double_int_to_tree (sizetype,
- tree_to_double_int (TYPE_MAX_VALUE (sizetype)));
SET_TYPE_MODE (bitsizetype, smallest_mode_for_size (bprecision, MODE_INT));
TYPE_ALIGN (bitsizetype) = GET_MODE_ALIGNMENT (TYPE_MODE (bitsizetype));
@@ -2466,11 +2487,6 @@ initialize_sizetypes (void)
= size_int (GET_MODE_SIZE (TYPE_MODE (bitsizetype)));
set_min_and_max_values_for_integral_type (bitsizetype, bprecision,
/*is_unsigned=*/true);
- /* bitsizetype is unsigned but we need to fix TYPE_MAX_VALUE so that it is
- sign-extended in a way consistent with force_fit_type. */
- TYPE_MAX_VALUE (bitsizetype)
- = double_int_to_tree (bitsizetype,
- tree_to_double_int (TYPE_MAX_VALUE (bitsizetype)));
/* Create the signed variants of *sizetype. */
ssizetype = make_signed_type (TYPE_PRECISION (sizetype));