This patch changes the type of stack_var::size from HOST_WIDE_INT
to poly_uint64. The difference in signedness is because the
field was set by:
v->size = tree_to_uhwi (size);
2017-10-23 Richard Sandiford
Alan Hayward
David Sherwood
gcc/
* cfgexpand.c (stack_var::size): Change from a HOST_WIDE_INT
to a poly_uint64.
(add_stack_var, stack_var_cmp, partition_stack_vars)
(dump_stack_var_partition): Update accordingly.
(alloc_stack_frame_space): Take the size as a poly_int64 rather
than a HOST_WIDE_INT.
(expand_stack_vars, expand_one_stack_var_1): Handle polynomial sizes.
(defer_stack_allocation, estimated_stack_frame_size): Likewise.
(account_stack_vars, expand_one_var): Likewise. Return a poly_uint64
rather than a HOST_WIDE_INT.
Index: gcc/cfgexpand.c
===
--- gcc/cfgexpand.c 2017-10-23 17:18:53.827515374 +0100
+++ gcc/cfgexpand.c 2017-10-23 17:19:04.559212322 +0100
@@ -314,7 +314,7 @@ struct stack_var
/* Initially, the size of the variable. Later, the size of the partition,
if this variable becomes it's partition's representative. */
- HOST_WIDE_INT size;
+ poly_uint64 size;
/* The *byte* alignment required for this variable. Or as, with the
size, the alignment for this partition. */
@@ -390,7 +390,7 @@ align_base (HOST_WIDE_INT base, unsigned
Return the frame offset. */
static poly_int64
-alloc_stack_frame_space (HOST_WIDE_INT size, unsigned HOST_WIDE_INT align)
+alloc_stack_frame_space (poly_int64 size, unsigned HOST_WIDE_INT align)
{
poly_int64 offset, new_frame_offset;
@@ -443,10 +443,10 @@ add_stack_var (tree decl)
tree size = TREE_CODE (decl) == SSA_NAME
? TYPE_SIZE_UNIT (TREE_TYPE (decl))
: DECL_SIZE_UNIT (decl);
- v->size = tree_to_uhwi (size);
+ v->size = tree_to_poly_uint64 (size);
/* Ensure that all variables have size, so that != for any two
variables that are simultaneously live. */
- if (v->size == 0)
+ if (known_zero (v->size))
v->size = 1;
v->alignb = align_local_variable (decl);
/* An alignment of zero can mightily confuse us later. */
@@ -676,8 +676,8 @@ stack_var_cmp (const void *a, const void
size_t ib = *(const size_t *)b;
unsigned int aligna = stack_vars[ia].alignb;
unsigned int alignb = stack_vars[ib].alignb;
- HOST_WIDE_INT sizea = stack_vars[ia].size;
- HOST_WIDE_INT sizeb = stack_vars[ib].size;
+ poly_int64 sizea = stack_vars[ia].size;
+ poly_int64 sizeb = stack_vars[ib].size;
tree decla = stack_vars[ia].decl;
tree declb = stack_vars[ib].decl;
bool largea, largeb;
@@ -690,10 +690,9 @@ stack_var_cmp (const void *a, const void
return (int)largeb - (int)largea;
/* Secondary compare on size, decreasing */
- if (sizea > sizeb)
-return -1;
- if (sizea < sizeb)
-return 1;
+ int diff = compare_sizes_for_sort (sizeb, sizea);
+ if (diff != 0)
+return diff;
/* Tertiary compare on true alignment, decreasing. */
if (aligna < alignb)
@@ -904,7 +903,7 @@ partition_stack_vars (void)
{
size_t i = stack_vars_sorted[si];
unsigned int ialign = stack_vars[i].alignb;
- HOST_WIDE_INT isize = stack_vars[i].size;
+ poly_int64 isize = stack_vars[i].size;
/* Ignore objects that aren't partition representatives. If we
see a var that is not a partition representative, it must
@@ -916,7 +915,7 @@ partition_stack_vars (void)
{
size_t j = stack_vars_sorted[sj];
unsigned int jalign = stack_vars[j].alignb;
- HOST_WIDE_INT jsize = stack_vars[j].size;
+ poly_int64 jsize = stack_vars[j].size;
/* Ignore objects that aren't partition representatives. */
if (stack_vars[j].representative != j)
@@ -932,8 +931,8 @@ partition_stack_vars (void)
sizes, as the shorter vars wouldn't be adequately protected.
Don't do that for "large" (unsupported) alignment objects,
those aren't protected anyway. */
- if ((asan_sanitize_stack_p ())
- && isize != jsize
+ if (asan_sanitize_stack_p ()
+ && may_ne (isize, jsize)
&& ialign * BITS_PER_UNIT <= MAX_SUPPORTED_STACK_ALIGNMENT)
break;
@@ -964,9 +963,9 @@ dump_stack_var_partition (void)
if (stack_vars[i].representative != i)
continue;
- fprintf (dump_file, "Partition %lu: size " HOST_WIDE_INT_PRINT_DEC
- " align %u\n", (unsigned long) i, stack_vars[i].size,
- stack_vars[i].alignb);
+ fprintf (dump_file, "Partition %lu: size ", (unsigned long) i);
+ print_dec (stack_vars[i].size, dump_file);
+ fprintf (dump_file, " align %u\n", stack_vars[i].alignb);
for (j = i; j != EOC; j = stack_vars[j].next)