Provide extra checking for phi argument access from edge
The following adds checking that the edge we query an associated PHI arg for is related to the PHI node. Triggered by questionable code in one of my reviews. * gimple.h (gimple_phi_arg): New const overload. (gimple_phi_arg_def): Make gimple arg const. (gimple_phi_arg_def_from_edge): New inline function. * tree-phinodes.h (gimple_phi_arg_imm_use_ptr_from_edge): Likewise. * tree-ssa-operands.h (PHI_ARG_DEF_FROM_EDGE): Direct to new inline function. (PHI_ARG_DEF_PTR_FROM_EDGE): Likewise.
This commit is contained in:
parent
407d68daed
commit
b77161e60b
3 changed files with 33 additions and 3 deletions
25
gcc/gimple.h
25
gcc/gimple.h
|
@ -4633,6 +4633,13 @@ gimple_phi_arg (const gphi *gs, unsigned index)
|
|||
return &(gs->args[index]);
|
||||
}
|
||||
|
||||
inline const phi_arg_d *
|
||||
gimple_phi_arg (const gimple *gs, unsigned index)
|
||||
{
|
||||
const gphi *phi_stmt = as_a <const gphi *> (gs);
|
||||
return gimple_phi_arg (phi_stmt, index);
|
||||
}
|
||||
|
||||
inline struct phi_arg_d *
|
||||
gimple_phi_arg (gimple *gs, unsigned index)
|
||||
{
|
||||
|
@ -4678,11 +4685,27 @@ gimple_phi_arg_def (const gphi *gs, size_t index)
|
|||
}
|
||||
|
||||
inline tree
|
||||
gimple_phi_arg_def (gimple *gs, size_t index)
|
||||
gimple_phi_arg_def (const gimple *gs, size_t index)
|
||||
{
|
||||
return gimple_phi_arg (gs, index)->def;
|
||||
}
|
||||
|
||||
/* Return the tree operand for the argument associated with
|
||||
edge E of PHI node GS. */
|
||||
|
||||
inline tree
|
||||
gimple_phi_arg_def_from_edge (const gphi *gs, const_edge e)
|
||||
{
|
||||
gcc_checking_assert (e->dest == gimple_bb (gs));
|
||||
return gimple_phi_arg (gs, e->dest_idx)->def;
|
||||
}
|
||||
|
||||
inline tree
|
||||
gimple_phi_arg_def_from_edge (const gimple *gs, const_edge e)
|
||||
{
|
||||
gcc_checking_assert (e->dest == gimple_bb (gs));
|
||||
return gimple_phi_arg (gs, e->dest_idx)->def;
|
||||
}
|
||||
|
||||
/* Return a pointer to the tree operand for argument I of phi node PHI. */
|
||||
|
||||
|
|
|
@ -37,6 +37,13 @@ gimple_phi_arg_imm_use_ptr (gimple *gs, int i)
|
|||
return &gimple_phi_arg (gs, i)->imm_use;
|
||||
}
|
||||
|
||||
inline use_operand_p
|
||||
gimple_phi_arg_imm_use_ptr_from_edge (gimple *gs, const_edge e)
|
||||
{
|
||||
gcc_checking_assert (e->dest == gimple_bb (gs));
|
||||
return &gimple_phi_arg (gs, e->dest_idx)->imm_use;
|
||||
}
|
||||
|
||||
/* Return the phi argument which contains the specified use. */
|
||||
|
||||
inline int
|
||||
|
|
|
@ -83,9 +83,9 @@ struct GTY(()) ssa_operands {
|
|||
#define SET_PHI_ARG_DEF(PHI, I, V) \
|
||||
SET_USE (PHI_ARG_DEF_PTR ((PHI), (I)), (V))
|
||||
#define PHI_ARG_DEF_FROM_EDGE(PHI, E) \
|
||||
PHI_ARG_DEF ((PHI), (E)->dest_idx)
|
||||
gimple_phi_arg_def_from_edge ((PHI), (E))
|
||||
#define PHI_ARG_DEF_PTR_FROM_EDGE(PHI, E) \
|
||||
PHI_ARG_DEF_PTR ((PHI), (E)->dest_idx)
|
||||
gimple_phi_arg_imm_use_ptr_from_edge ((PHI), (E))
|
||||
#define PHI_ARG_INDEX_FROM_USE(USE) phi_arg_index_from_use (USE)
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue