summaryrefslogtreecommitdiff
path: root/gcc/stor-layout.c
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/stor-layout.c')
-rw-r--r--gcc/stor-layout.c195
1 files changed, 68 insertions, 127 deletions
diff --git a/gcc/stor-layout.c b/gcc/stor-layout.c
index 6f6b3107841..a9ee566d604 100644
--- a/gcc/stor-layout.c
+++ b/gcc/stor-layout.c
@@ -331,9 +331,9 @@ mode_for_size_tree (const_tree size, enum mode_class mclass, int limit)
unsigned HOST_WIDE_INT uhwi;
unsigned int ui;
- if (!host_integerp (size, 1))
+ if (!tree_fits_uhwi_p (size))
return BLKmode;
- uhwi = tree_low_cst (size, 1);
+ uhwi = tree_to_uhwi (size);
ui = uhwi;
if (uhwi != ui)
return BLKmode;
@@ -481,10 +481,10 @@ mode_for_array (tree elem_type, tree size)
return TYPE_MODE (elem_type);
limit_p = true;
- if (host_integerp (size, 1) && host_integerp (elem_size, 1))
+ if (tree_fits_uhwi_p (size) && tree_fits_uhwi_p (elem_size))
{
- int_size = tree_low_cst (size, 1);
- int_elem_size = tree_low_cst (elem_size, 1);
+ int_size = tree_to_uhwi (size);
+ int_elem_size = tree_to_uhwi (elem_size);
if (int_elem_size > 0
&& int_size % int_elem_size == 0
&& targetm.array_mode_supported_p (TYPE_MODE (elem_type),
@@ -690,7 +690,7 @@ layout_decl (tree decl, unsigned int known_align)
if (size != 0 && TREE_CODE (size) == INTEGER_CST
&& compare_tree_int (size, larger_than_size) > 0)
{
- int size_as_int = TREE_INT_CST_LOW (size);
+ int size_as_int = tree_to_hwi (size);
if (compare_tree_int (size, size_as_int) == 0)
warning (OPT_Wlarger_than_, "size of %q+D is %d bytes", decl, size_as_int);
@@ -1055,7 +1055,7 @@ excess_unit_span (HOST_WIDE_INT byte_offset, HOST_WIDE_INT bit_offset,
offset = offset % align;
return ((offset + size + align - 1) / align
- > ((unsigned HOST_WIDE_INT) tree_low_cst (TYPE_SIZE (type), 1)
+ > ((unsigned HOST_WIDE_INT) tree_to_uhwi (TYPE_SIZE (type))
/ align));
}
#endif
@@ -1115,14 +1115,14 @@ place_field (record_layout_info rli, tree field)
/* Work out the known alignment so far. Note that A & (-A) is the
value of the least-significant bit in A that is one. */
if (! integer_zerop (rli->bitpos))
- known_align = (tree_low_cst (rli->bitpos, 1)
- & - tree_low_cst (rli->bitpos, 1));
+ known_align = (tree_to_uhwi (rli->bitpos)
+ & - tree_to_uhwi (rli->bitpos));
else if (integer_zerop (rli->offset))
known_align = 0;
- else if (host_integerp (rli->offset, 1))
+ else if (tree_fits_uhwi_p (rli->offset))
known_align = (BITS_PER_UNIT
- * (tree_low_cst (rli->offset, 1)
- & - tree_low_cst (rli->offset, 1)));
+ * (tree_to_uhwi (rli->offset)
+ & - tree_to_uhwi (rli->offset)));
else
known_align = rli->offset_align;
@@ -1196,15 +1196,16 @@ place_field (record_layout_info rli, tree field)
|| TYPE_ALIGN (type) <= BITS_PER_UNIT)
&& maximum_field_alignment == 0
&& ! integer_zerop (DECL_SIZE (field))
- && host_integerp (DECL_SIZE (field), 1)
- && host_integerp (rli->offset, 1)
- && host_integerp (TYPE_SIZE (type), 1))
+ && tree_fits_uhwi_p (DECL_SIZE (field))
+ /* BUG!!! rli->offset is checked as unsigned but used as signed. */
+ && tree_fits_uhwi_p (rli->offset)
+ && tree_fits_uhwi_p (TYPE_SIZE (type)))
{
unsigned int type_align = TYPE_ALIGN (type);
tree dsize = DECL_SIZE (field);
- HOST_WIDE_INT field_size = tree_low_cst (dsize, 1);
- HOST_WIDE_INT offset = tree_low_cst (rli->offset, 0);
- HOST_WIDE_INT bit_offset = tree_low_cst (rli->bitpos, 0);
+ HOST_WIDE_INT field_size = tree_to_uhwi (dsize);
+ HOST_WIDE_INT offset = tree_to_shwi (rli->offset);
+ HOST_WIDE_INT bit_offset = tree_to_shwi (rli->bitpos);
#ifdef ADJUST_FIELD_ALIGN
if (! TYPE_USER_ALIGN (type))
@@ -1240,15 +1241,16 @@ place_field (record_layout_info rli, tree field)
&& DECL_BIT_FIELD_TYPE (field)
&& ! DECL_PACKED (field)
&& ! integer_zerop (DECL_SIZE (field))
- && host_integerp (DECL_SIZE (field), 1)
- && host_integerp (rli->offset, 1)
- && host_integerp (TYPE_SIZE (type), 1))
+ && tree_fits_uhwi_p (DECL_SIZE (field))
+ /* BUG!!! rli->offset is checked as unsigned but used as signed. */
+ && tree_fits_shwi_p (rli->offset)
+ && tree_fits_uhwi_p (TYPE_SIZE (type)))
{
unsigned int type_align = TYPE_ALIGN (type);
tree dsize = DECL_SIZE (field);
- HOST_WIDE_INT field_size = tree_low_cst (dsize, 1);
- HOST_WIDE_INT offset = tree_low_cst (rli->offset, 0);
- HOST_WIDE_INT bit_offset = tree_low_cst (rli->bitpos, 0);
+ HOST_WIDE_INT field_size = tree_to_uhwi (dsize);
+ HOST_WIDE_INT offset = tree_to_shwi (rli->offset);
+ HOST_WIDE_INT bit_offset = tree_to_shwi (rli->bitpos);
#ifdef ADJUST_FIELD_ALIGN
if (! TYPE_USER_ALIGN (type))
@@ -1302,18 +1304,19 @@ place_field (record_layout_info rli, tree field)
if (DECL_BIT_FIELD_TYPE (field)
&& !integer_zerop (DECL_SIZE (field))
&& !integer_zerop (DECL_SIZE (rli->prev_field))
- && host_integerp (DECL_SIZE (rli->prev_field), 0)
- && host_integerp (TYPE_SIZE (type), 0)
+ && tree_fits_shwi_p (DECL_SIZE (rli->prev_field))
+ /* BUG!!! TYPE_SIZE (type) is checked as unsigned but used as signed. */
+ && tree_fits_shwi_p (TYPE_SIZE (type))
&& simple_cst_equal (TYPE_SIZE (type), TYPE_SIZE (prev_type)))
{
/* We're in the middle of a run of equal type size fields; make
sure we realign if we run out of bits. (Not decl size,
type size!) */
- HOST_WIDE_INT bitsize = tree_low_cst (DECL_SIZE (field), 1);
+ HOST_WIDE_INT bitsize = tree_to_uhwi (DECL_SIZE (field));
if (rli->remaining_in_alignment < bitsize)
{
- HOST_WIDE_INT typesize = tree_low_cst (TYPE_SIZE (type), 1);
+ HOST_WIDE_INT typesize = tree_to_uhwi (TYPE_SIZE (type));
/* out of bits; bump up to next 'word'. */
rli->bitpos
@@ -1385,13 +1388,13 @@ place_field (record_layout_info rli, tree field)
until we see a bitfield (and come by here again) we just skip
calculating it. */
if (DECL_SIZE (field) != NULL
- && host_integerp (TYPE_SIZE (TREE_TYPE (field)), 1)
- && host_integerp (DECL_SIZE (field), 1))
+ && tree_fits_uhwi_p (TYPE_SIZE (TREE_TYPE (field)))
+ && tree_fits_uhwi_p (DECL_SIZE (field)))
{
unsigned HOST_WIDE_INT bitsize
- = tree_low_cst (DECL_SIZE (field), 1);
+ = tree_to_uhwi (DECL_SIZE (field));
unsigned HOST_WIDE_INT typesize
- = tree_low_cst (TYPE_SIZE (TREE_TYPE (field)), 1);
+ = tree_to_uhwi (TYPE_SIZE (TREE_TYPE (field)));
if (typesize < bitsize)
rli->remaining_in_alignment = 0;
@@ -1423,14 +1426,14 @@ place_field (record_layout_info rli, tree field)
approximate this by seeing if its position changed), lay out the field
again; perhaps we can use an integral mode for it now. */
if (! integer_zerop (DECL_FIELD_BIT_OFFSET (field)))
- actual_align = (tree_low_cst (DECL_FIELD_BIT_OFFSET (field), 1)
- & - tree_low_cst (DECL_FIELD_BIT_OFFSET (field), 1));
+ actual_align = (tree_to_uhwi (DECL_FIELD_BIT_OFFSET (field))
+ & - tree_to_uhwi (DECL_FIELD_BIT_OFFSET (field)));
else if (integer_zerop (DECL_FIELD_OFFSET (field)))
actual_align = MAX (BIGGEST_ALIGNMENT, rli->record_align);
- else if (host_integerp (DECL_FIELD_OFFSET (field), 1))
+ else if (tree_fits_uhwi_p (DECL_FIELD_OFFSET (field)))
actual_align = (BITS_PER_UNIT
- * (tree_low_cst (DECL_FIELD_OFFSET (field), 1)
- & - tree_low_cst (DECL_FIELD_OFFSET (field), 1)));
+ * (tree_to_uhwi (DECL_FIELD_OFFSET (field))
+ & - tree_to_uhwi (DECL_FIELD_OFFSET (field))));
else
actual_align = DECL_OFFSET_ALIGN (field);
/* ACTUAL_ALIGN is still the actual alignment *within the record* .
@@ -1586,7 +1589,7 @@ compute_record_mode (tree type)
line. */
SET_TYPE_MODE (type, BLKmode);
- if (! host_integerp (TYPE_SIZE (type), 1))
+ if (! tree_fits_uhwi_p (TYPE_SIZE (type)))
return;
/* A record which has any BLKmode members must itself be
@@ -1602,9 +1605,9 @@ compute_record_mode (tree type)
&& ! TYPE_NO_FORCE_BLK (TREE_TYPE (field))
&& !(TYPE_SIZE (TREE_TYPE (field)) != 0
&& integer_zerop (TYPE_SIZE (TREE_TYPE (field)))))
- || ! host_integerp (bit_position (field), 1)
+ || ! tree_fits_uhwi_p (bit_position (field))
|| DECL_SIZE (field) == 0
- || ! host_integerp (DECL_SIZE (field), 1))
+ || ! tree_fits_uhwi_p (DECL_SIZE (field)))
return;
/* If this field is the whole struct, remember its mode so
@@ -1623,8 +1626,8 @@ compute_record_mode (tree type)
matches the type's size. This only applies to RECORD_TYPE. This
does not apply to unions. */
if (TREE_CODE (type) == RECORD_TYPE && mode != VOIDmode
- && host_integerp (TYPE_SIZE (type), 1)
- && GET_MODE_BITSIZE (mode) == TREE_INT_CST_LOW (TYPE_SIZE (type)))
+ && tree_fits_uhwi_p (TYPE_SIZE (type))
+ && GET_MODE_BITSIZE (mode) == tree_to_uhwi (TYPE_SIZE (type)))
SET_TYPE_MODE (type, mode);
else
SET_TYPE_MODE (type, mode_for_size_tree (TYPE_SIZE (type), MODE_INT, 1));
@@ -1765,11 +1768,11 @@ finish_bitfield_representative (tree repr, tree field)
size = size_diffop (DECL_FIELD_OFFSET (field),
DECL_FIELD_OFFSET (repr));
- gcc_assert (host_integerp (size, 1));
- bitsize = (tree_low_cst (size, 1) * BITS_PER_UNIT
- + tree_low_cst (DECL_FIELD_BIT_OFFSET (field), 1)
- - tree_low_cst (DECL_FIELD_BIT_OFFSET (repr), 1)
- + tree_low_cst (DECL_SIZE (field), 1));
+ gcc_assert (tree_fits_uhwi_p (size));
+ bitsize = (tree_to_uhwi (size) * BITS_PER_UNIT
+ + tree_to_uhwi (DECL_FIELD_BIT_OFFSET (field))
+ - tree_to_uhwi (DECL_FIELD_BIT_OFFSET (repr))
+ + tree_to_uhwi (DECL_SIZE (field)));
/* Round up bitsize to multiples of BITS_PER_UNIT. */
bitsize = (bitsize + BITS_PER_UNIT - 1) & ~(BITS_PER_UNIT - 1);
@@ -1787,11 +1790,11 @@ finish_bitfield_representative (tree repr, tree field)
return;
maxsize = size_diffop (DECL_FIELD_OFFSET (nextf),
DECL_FIELD_OFFSET (repr));
- if (host_integerp (maxsize, 1))
+ if (tree_fits_uhwi_p (maxsize))
{
- maxbitsize = (tree_low_cst (maxsize, 1) * BITS_PER_UNIT
- + tree_low_cst (DECL_FIELD_BIT_OFFSET (nextf), 1)
- - tree_low_cst (DECL_FIELD_BIT_OFFSET (repr), 1));
+ maxbitsize = (tree_to_uhwi (maxsize) * BITS_PER_UNIT
+ + tree_to_uhwi (DECL_FIELD_BIT_OFFSET (nextf))
+ - tree_to_uhwi (DECL_FIELD_BIT_OFFSET (repr)));
/* If the group ends within a bitfield nextf does not need to be
aligned to BITS_PER_UNIT. Thus round up. */
maxbitsize = (maxbitsize + BITS_PER_UNIT - 1) & ~(BITS_PER_UNIT - 1);
@@ -1808,9 +1811,9 @@ finish_bitfield_representative (tree repr, tree field)
use bitsize as fallback for this case. */
tree maxsize = size_diffop (TYPE_SIZE_UNIT (DECL_CONTEXT (field)),
DECL_FIELD_OFFSET (repr));
- if (host_integerp (maxsize, 1))
- maxbitsize = (tree_low_cst (maxsize, 1) * BITS_PER_UNIT
- - tree_low_cst (DECL_FIELD_BIT_OFFSET (repr), 1));
+ if (tree_fits_uhwi_p (maxsize))
+ maxbitsize = (tree_to_uhwi (maxsize) * BITS_PER_UNIT
+ - tree_to_uhwi (DECL_FIELD_BIT_OFFSET (repr)));
else
maxbitsize = bitsize;
}
@@ -1921,8 +1924,8 @@ finish_bitfield_layout (record_layout_info rli)
representative to be generated. That will at most
generate worse code but still maintain correctness with
respect to the C++ memory model. */
- else if (!((host_integerp (DECL_FIELD_OFFSET (repr), 1)
- && host_integerp (DECL_FIELD_OFFSET (field), 1))
+ else if (!((tree_fits_uhwi_p (DECL_FIELD_OFFSET (repr))
+ && tree_fits_uhwi_p (DECL_FIELD_OFFSET (field)))
|| operand_equal_p (DECL_FIELD_OFFSET (repr),
DECL_FIELD_OFFSET (field), 0)))
{
@@ -2205,12 +2208,8 @@ layout_type (tree type)
&& tree_int_cst_lt (ub, lb))
{
unsigned prec = TYPE_PRECISION (TREE_TYPE (lb));
- lb = double_int_to_tree
- (ssizetype,
- tree_to_double_int (lb).sext (prec));
- ub = double_int_to_tree
- (ssizetype,
- tree_to_double_int (ub).sext (prec));
+ lb = wide_int_to_tree (ssizetype, addr_wide_int (lb).sext (prec));
+ ub = wide_int_to_tree (ssizetype, addr_wide_int (ub).sext (prec));
}
length
= fold_convert (sizetype,
@@ -2486,16 +2485,14 @@ initialize_sizetypes (void)
TYPE_ALIGN (sizetype) = GET_MODE_ALIGNMENT (TYPE_MODE (sizetype));
TYPE_SIZE (sizetype) = bitsize_int (precision);
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);
+ set_min_and_max_values_for_integral_type (sizetype, precision, UNSIGNED);
SET_TYPE_MODE (bitsizetype, smallest_mode_for_size (bprecision, MODE_INT));
TYPE_ALIGN (bitsizetype) = GET_MODE_ALIGNMENT (TYPE_MODE (bitsizetype));
TYPE_SIZE (bitsizetype) = bitsize_int (bprecision);
TYPE_SIZE_UNIT (bitsizetype)
= size_int (GET_MODE_SIZE (TYPE_MODE (bitsizetype)));
- set_min_and_max_values_for_integral_type (bitsizetype, bprecision,
- /*is_unsigned=*/true);
+ set_min_and_max_values_for_integral_type (bitsizetype, bprecision, UNSIGNED);
/* Create the signed variants of *sizetype. */
ssizetype = make_signed_type (TYPE_PRECISION (sizetype));
@@ -2515,52 +2512,10 @@ initialize_sizetypes (void)
void
set_min_and_max_values_for_integral_type (tree type,
int precision,
- bool is_unsigned)
+ signop sgn)
{
- tree min_value;
- tree max_value;
-
- if (is_unsigned)
- {
- min_value = build_int_cst (type, 0);
- max_value
- = build_int_cst_wide (type, precision - HOST_BITS_PER_WIDE_INT >= 0
- ? -1
- : ((HOST_WIDE_INT) 1 << precision) - 1,
- precision - HOST_BITS_PER_WIDE_INT > 0
- ? ((unsigned HOST_WIDE_INT) ~0
- >> (HOST_BITS_PER_WIDE_INT
- - (precision - HOST_BITS_PER_WIDE_INT)))
- : 0);
- }
- else
- {
- min_value
- = build_int_cst_wide (type,
- (precision - HOST_BITS_PER_WIDE_INT > 0
- ? 0
- : (HOST_WIDE_INT) (-1) << (precision - 1)),
- (((HOST_WIDE_INT) (-1)
- << (precision - HOST_BITS_PER_WIDE_INT - 1 > 0
- ? precision - HOST_BITS_PER_WIDE_INT - 1
- : 0))));
- max_value
- = build_int_cst_wide (type,
- (precision - HOST_BITS_PER_WIDE_INT > 0
- ? -1
- : (HOST_WIDE_INT)
- (((unsigned HOST_WIDE_INT) 1
- << (precision - 1)) - 1)),
- (precision - HOST_BITS_PER_WIDE_INT - 1 > 0
- ? (HOST_WIDE_INT)
- ((((unsigned HOST_WIDE_INT) 1
- << (precision - HOST_BITS_PER_WIDE_INT
- - 1))) - 1)
- : 0));
- }
-
- TYPE_MIN_VALUE (type) = min_value;
- TYPE_MAX_VALUE (type) = max_value;
+ TYPE_MIN_VALUE (type) = wide_int_to_tree (type, wide_int::min_value (precision, sgn));
+ TYPE_MAX_VALUE (type) = wide_int_to_tree (type, wide_int::max_value (precision, sgn));
}
/* Set the extreme values of TYPE based on its precision in bits,
@@ -2573,14 +2528,7 @@ fixup_signed_type (tree type)
{
int precision = TYPE_PRECISION (type);
- /* We can not represent properly constants greater then
- HOST_BITS_PER_DOUBLE_INT, still we need the types
- as they are used by i386 vector extensions and friends. */
- if (precision > HOST_BITS_PER_DOUBLE_INT)
- precision = HOST_BITS_PER_DOUBLE_INT;
-
- set_min_and_max_values_for_integral_type (type, precision,
- /*is_unsigned=*/false);
+ set_min_and_max_values_for_integral_type (type, precision, SIGNED);
/* Lay out the type: set its alignment, size, etc. */
layout_type (type);
@@ -2595,16 +2543,9 @@ fixup_unsigned_type (tree type)
{
int precision = TYPE_PRECISION (type);
- /* We can not represent properly constants greater then
- HOST_BITS_PER_DOUBLE_INT, still we need the types
- as they are used by i386 vector extensions and friends. */
- if (precision > HOST_BITS_PER_DOUBLE_INT)
- precision = HOST_BITS_PER_DOUBLE_INT;
-
TYPE_UNSIGNED (type) = 1;
- set_min_and_max_values_for_integral_type (type, precision,
- /*is_unsigned=*/true);
+ set_min_and_max_values_for_integral_type (type, precision, UNSIGNED);
/* Lay out the type: set its alignment, size, etc. */
layout_type (type);