Make assert in gimple_phi_arg more strict
2017-07-20 Tom de Vries <tom@codesourcery.com>
* gimple.h (gimple_phi_arg): Make assert more strict.
* tree-phinodes.c (make_phi_node, resize_phi_node): Set nargs
temporarily to capacity, to be able to access the entire args array.
(reserve_phi_args_for_new_edge): Increase nargs earlier.
---
gcc/gimple.h | 2 +-
gcc/tree-phinodes.c | 15 ++++++++++++---
2 files changed, 13 insertions(+), 4 deletions(-)
@@ -4341,7 +4341,7 @@ static inline struct phi_arg_d *
gimple_phi_arg (gimple *gs, unsigned index)
{
gphi *phi_stmt = as_a <gphi *> (gs);
- gcc_gimple_checking_assert (index < phi_stmt->capacity);
+ gcc_gimple_checking_assert (index < phi_stmt->nargs);
return &(phi_stmt->args[index]);
}
@@ -190,6 +190,10 @@ make_phi_node (tree var, int len)
else
gimple_phi_set_result (phi, make_ssa_name (var, phi));
+ /* Temporarily set nargs to capacity, to be able to initialize the entire args
+ array. */
+ unsigned nargs = phi->nargs;
+ phi->nargs = phi->capacity;
for (i = 0; i < capacity; i++)
{
use_operand_p imm;
@@ -201,6 +205,7 @@ make_phi_node (tree var, int len)
imm->next = NULL;
imm->loc.stmt = phi;
}
+ phi->nargs = nargs;
return phi;
}
@@ -260,7 +265,11 @@ resize_phi_node (gphi *phi, size_t len)
new_phi->capacity = len;
- for (i = gimple_phi_num_args (new_phi); i < len; i++)
+ unsigned nargs = gimple_phi_num_args (new_phi);
+ /* Temporarily set nargs to capacity, to be able to initialize the entire args
+ array. */
+ new_phi->nargs = new_phi->capacity;
+ for (i = nargs; i < len; i++)
{
use_operand_p imm;
@@ -271,6 +280,7 @@ resize_phi_node (gphi *phi, size_t len)
imm->next = NULL;
imm->loc.stmt = new_phi;
}
+ new_phi->nargs = nargs;
return new_phi;
}
@@ -307,10 +317,9 @@ reserve_phi_args_for_new_edge (basic_block bb)
example, the loop optimizer duplicates several basic blocks,
redirects edges, and then fixes up PHI arguments later in
batch. */
+ stmt->nargs++;
SET_PHI_ARG_DEF (stmt, len - 1, NULL_TREE);
gimple_phi_arg_set_location (stmt, len - 1, UNKNOWN_LOCATION);
-
- stmt->nargs++;
}
}