/* Purge dead heap-allocated regions from dynamic extents. */
for (const svalue *sval : dead_svals)
- if (const region_svalue *region_sval = sval->dyn_cast_region_svalue ())
- {
- const region *reg = region_sval->get_pointee ();
- if (reg->get_kind () == RK_HEAP_ALLOCATED)
- dest_state.m_region_model->unset_dynamic_extents (reg);
- }
+ if (const region *reg = sval->maybe_get_region ())
+ if (reg->get_kind () == RK_HEAP_ALLOCATED)
+ dest_state.m_region_model->unset_dynamic_extents (reg);
}
#if CHECKING_P
/* Ideally we would bifurcate state here between the
error vs no error cases. */
const svalue *ptr_sval = cd.get_arg_svalue (0);
- if (const region_svalue *ptr_to_region_sval
- = ptr_sval->dyn_cast_region_svalue ())
+ if (const region *reg = ptr_sval->maybe_get_region ())
{
- const region *reg = ptr_to_region_sval->get_pointee ();
const region *base_reg = reg->get_base_region ();
const svalue *new_sval = cd.get_or_create_conjured_svalue (base_reg);
purge_state_involving (new_sval, cd.get_ctxt ());
region_model::impl_call_fread (const call_details &cd)
{
const svalue *ptr_sval = cd.get_arg_svalue (0);
- if (const region_svalue *ptr_to_region_sval
- = ptr_sval->dyn_cast_region_svalue ())
+ if (const region *reg = ptr_sval->maybe_get_region ())
{
- const region *reg = ptr_to_region_sval->get_pointee ();
const region *base_reg = reg->get_base_region ();
const svalue *new_sval = cd.get_or_create_conjured_svalue (base_reg);
purge_state_involving (new_sval, cd.get_ctxt ());
region_model::impl_call_free (const call_details &cd)
{
const svalue *ptr_sval = cd.get_arg_svalue (0);
- if (const region_svalue *ptr_to_region_sval
- = ptr_sval->dyn_cast_region_svalue ())
+ if (const region *freed_reg = ptr_sval->maybe_get_region ())
{
/* If the ptr points to an underlying heap region, delete it,
poisoning pointers. */
- const region *freed_reg = ptr_to_region_sval->get_pointee ();
unbind_region_and_descendents (freed_reg, POISON_KIND_FREED);
m_dynamic_extents.remove (freed_reg);
}
region_model::impl_call_operator_delete (const call_details &cd)
{
const svalue *ptr_sval = cd.get_arg_svalue (0);
- if (const region_svalue *ptr_to_region_sval
- = ptr_sval->dyn_cast_region_svalue ())
+ if (const region *freed_reg = ptr_sval->maybe_get_region ())
{
/* If the ptr points to an underlying heap region, delete it,
poisoning pointers. */
- const region *freed_reg = ptr_to_region_sval->get_pointee ();
unbind_region_and_descendents (freed_reg, POISON_KIND_FREED);
}
return false;
renumbering. */
const svalue *new_q_sval = model.get_rvalue (q, &ctxt);
ASSERT_EQ (new_q_sval->get_kind (), SK_REGION);
- ASSERT_EQ (new_q_sval->dyn_cast_region_svalue ()->get_pointee (),
+ ASSERT_EQ (new_q_sval->maybe_get_region (),
model.get_lvalue (p, &ctxt));
/* Verify that top of stack has been updated. */
model0.set_value (q_in_first_frame, sval_ptr, NULL);
/* Verify that it's pointing at the newer frame. */
- const region *reg_pointee
- = sval_ptr->dyn_cast_region_svalue ()->get_pointee ();
+ const region *reg_pointee = sval_ptr->maybe_get_region ();
ASSERT_EQ (reg_pointee->get_parent_region (), reg_2nd_frame);
model0.canonicalize ();
return NULL_TREE;
}
+/* If this svalue is a region_svalue, return the region it points to.
+ Otherwise return NULL. */
+
+const region *
+svalue::maybe_get_region () const
+{
+ if (const region_svalue *region_sval = dyn_cast_region_svalue ())
+ return region_sval->get_pointee ();
+ else
+ return NULL;
+}
+
/* If this svalue is a cast (i.e a unaryop NOP_EXPR or VIEW_CONVERT_EXPR),
return the underlying svalue.
Otherwise return NULL. */