Skip to content

Commit c199723

Browse files
committed
analyzer: simplify store::eval_alias
I have followup patches that add new conditions to store::eval_alias. Rather than duplicate all conditions for symmetry, split it up and call it on both (A, B) and (B, A). gcc/analyzer/ChangeLog: * store.cc (store::eval_alias): Make const. Split out 2nd half into store::eval_alias_1 and call it twice for symmetry, avoiding test duplication. (store::eval_alias_1): New function, split out from the above. * store.h (store::eval_alias): Make const. (store::eval_alias_1): New decl.
1 parent 294b6da commit c199723

File tree

2 files changed

+27
-22
lines changed

2 files changed

+27
-22
lines changed

gcc/analyzer/store.cc

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1544,7 +1544,7 @@ store::set_value (store_manager *mgr, const region *lhs_reg,
15441544

15451545
tristate
15461546
store::eval_alias (const region *base_reg_a,
1547-
const region *base_reg_b)
1547+
const region *base_reg_b) const
15481548
{
15491549
/* SSA names can't alias. */
15501550
tree decl_a = base_reg_a->maybe_get_decl ();
@@ -1554,31 +1554,34 @@ store::eval_alias (const region *base_reg_a,
15541554
if (decl_b && TREE_CODE (decl_b) == SSA_NAME)
15551555
return tristate::TS_FALSE;
15561556

1557+
/* Try both ways, for symmetry. */
1558+
tristate ts_ab = eval_alias_1 (base_reg_a, base_reg_b);
1559+
if (ts_ab.is_false ())
1560+
return tristate::TS_FALSE;
1561+
tristate ts_ba = eval_alias_1 (base_reg_b, base_reg_a);
1562+
if (ts_ba.is_false ())
1563+
return tristate::TS_FALSE;
1564+
return tristate::TS_UNKNOWN;
1565+
}
1566+
1567+
/* Half of store::eval_alias; called twice for symmetry. */
1568+
1569+
tristate
1570+
store::eval_alias_1 (const region *base_reg_a,
1571+
const region *base_reg_b) const
1572+
{
15571573
if (const symbolic_region *sym_reg_a
15581574
= base_reg_a->dyn_cast_symbolic_region ())
15591575
{
15601576
const svalue *sval_a = sym_reg_a->get_pointer ();
1561-
if (sval_a->get_kind () == SK_INITIAL
1562-
&& decl_b
1563-
&& !is_global_var (decl_b))
1564-
{
1565-
/* The initial value of a pointer can't point to a local. */
1566-
return tristate::TS_FALSE;
1567-
}
1568-
}
1569-
if (const symbolic_region *sym_reg_b
1570-
= base_reg_b->dyn_cast_symbolic_region ())
1571-
{
1572-
const svalue *sval_b = sym_reg_b->get_pointer ();
1573-
if (sval_b->get_kind () == SK_INITIAL
1574-
&& decl_a
1575-
&& !is_global_var (decl_a))
1576-
{
1577-
/* The initial value of a pointer can't point to a local. */
1578-
return tristate::TS_FALSE;
1579-
}
1577+
if (sval_a->get_kind () == SK_INITIAL)
1578+
if (tree decl_b = base_reg_b->maybe_get_decl ())
1579+
if (!is_global_var (decl_b))
1580+
{
1581+
/* The initial value of a pointer can't point to a local. */
1582+
return tristate::TS_FALSE;
1583+
}
15801584
}
1581-
15821585
return tristate::TS_UNKNOWN;
15831586
}
15841587

gcc/analyzer/store.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ class store
553553
cluster_map_t::iterator end () const { return m_cluster_map.end (); }
554554

555555
tristate eval_alias (const region *base_reg_a,
556-
const region *base_reg_b);
556+
const region *base_reg_b) const;
557557

558558
template <typename BindingVisitor>
559559
void for_each_binding (BindingVisitor &v)
@@ -569,6 +569,8 @@ class store
569569

570570
private:
571571
void remove_overlapping_bindings (store_manager *mgr, const region *reg);
572+
tristate eval_alias_1 (const region *base_reg_a,
573+
const region *base_reg_b) const;
572574

573575
cluster_map_t m_cluster_map;
574576

0 commit comments

Comments
 (0)