aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Biener <rguenther@suse.de>2023-07-14 10:01:39 +0200
committerRichard Biener <rguenther@suse.de>2023-07-14 10:35:41 +0200
commitb77161e60bce7b4416319defe5f141f14fd375c4 (patch)
tree6a7a4fbb249e39904b4929e69ec18d60cd40532b
parent407d68daed00e040a7d9545b2a18aa27bf93a106 (diff)
downloadgcc-b77161e60bce7b4416319defe5f141f14fd375c4.zip
gcc-b77161e60bce7b4416319defe5f141f14fd375c4.tar.gz
gcc-b77161e60bce7b4416319defe5f141f14fd375c4.tar.bz2
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.
-rw-r--r--gcc/gimple.h25
-rw-r--r--gcc/tree-phinodes.h7
-rw-r--r--gcc/tree-ssa-operands.h4
3 files changed, 33 insertions, 3 deletions
diff --git a/gcc/gimple.h b/gcc/gimple.h
index daf5524..d3750f9 100644
--- a/gcc/gimple.h
+++ b/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. */
diff --git a/gcc/tree-phinodes.h b/gcc/tree-phinodes.h
index 932a461..be114e3 100644
--- a/gcc/tree-phinodes.h
+++ b/gcc/tree-phinodes.h
@@ -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
diff --git a/gcc/tree-ssa-operands.h b/gcc/tree-ssa-operands.h
index ae36bcd..c7b74e0 100644
--- a/gcc/tree-ssa-operands.h
+++ b/gcc/tree-ssa-operands.h
@@ -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)