@@ -2321,6 +2321,10 @@ const svalue *
region_model::get_store_value (const region *reg,
region_model_context *ctxt) const
{
+ /* Getting the value of an empty region gives an unknown_svalue. */
+ if (reg->empty_p ())
+ return m_mgr->get_or_create_unknown_svalue (reg->get_type ());
+
check_region_for_read (reg, ctxt);
/* Special-case: handle var_decls in the constant pool. */
@@ -3159,6 +3163,10 @@ region_model::set_value (const region *lhs_reg, const svalue *rhs_sval,
gcc_assert (lhs_reg);
gcc_assert (rhs_sval);
+ /* Setting the value of an empty region is a no-op. */
+ if (lhs_reg->empty_p ())
+ return;
+
check_region_size (lhs_reg, rhs_sval, ctxt);
check_region_for_write (lhs_reg, ctxt);
@@ -671,6 +671,18 @@ region::symbolic_p () const
return get_kind () == RK_SYMBOLIC;
}
+/* Return true if this region is known to be zero bits in size. */
+
+bool
+region::empty_p () const
+{
+ bit_size_t num_bits;
+ if (get_bit_size (&num_bits))
+ if (num_bits == 0)
+ return true;
+ return false;
+}
+
/* Return true if this is a region for a decl with name DECL_NAME.
Intended for use when debugging (for assertions and conditional
breakpoints). */
@@ -233,6 +233,8 @@ public:
bool is_named_decl_p (const char *decl_name) const;
+ bool empty_p () const;
+
protected:
region (complexity c, unsigned id, const region *parent, tree type);
@@ -813,7 +813,11 @@ same_binding_p (const region *reg_a, const region *reg_b,
{
if (reg_a->get_base_region () != reg_b->get_base_region ())
return false;
+ if (reg_a->empty_p ())
+ return false;
const binding_key *bind_key_a = binding_key::make (store_mgr, reg_a);
+ if (reg_b->empty_p ())
+ return false;
const binding_key *bind_key_b = binding_key::make (store_mgr, reg_b);
return bind_key_a == bind_key_b;
}
@@ -127,8 +127,12 @@ binding_key::make (store_manager *mgr, const region *r)
{
bit_size_t bit_size;
if (r->get_bit_size (&bit_size))
- return mgr->get_concrete_binding (offset.get_bit_offset (),
- bit_size);
+ {
+ /* Must be non-empty. */
+ gcc_assert (bit_size > 0);
+ return mgr->get_concrete_binding (offset.get_bit_offset (),
+ bit_size);
+ }
else
return mgr->get_symbolic_binding (r);
}
@@ -1464,6 +1468,9 @@ binding_cluster::mark_region_as_unknown (store_manager *mgr,
const region *reg_for_overlap,
uncertainty_t *uncertainty)
{
+ if (reg_to_bind->empty_p ())
+ return;
+
remove_overlapping_bindings (mgr, reg_for_overlap, uncertainty);
/* Add a default binding to "unknown". */
@@ -1516,6 +1523,8 @@ const svalue *
binding_cluster::get_binding (store_manager *mgr,
const region *reg) const
{
+ if (reg->empty_p ())
+ return NULL;
const binding_key *reg_binding = binding_key::make (mgr, reg);
const svalue *sval = m_map.get (reg_binding);
if (sval)
@@ -1800,6 +1809,8 @@ binding_cluster::remove_overlapping_bindings (store_manager *mgr,
const region *reg,
uncertainty_t *uncertainty)
{
+ if (reg->empty_p ())
+ return;
const binding_key *reg_binding = binding_key::make (mgr, reg);
const region *cluster_base_reg = get_base_region ();
@@ -2007,11 +2018,14 @@ binding_cluster::on_unknown_fncall (const gcall *call,
{
m_map.empty ();
- /* Bind it to a new "conjured" value using CALL. */
- const svalue *sval
- = mgr->get_svalue_manager ()->get_or_create_conjured_svalue
+ if (!m_base_region->empty_p ())
+ {
+ /* Bind it to a new "conjured" value using CALL. */
+ const svalue *sval
+ = mgr->get_svalue_manager ()->get_or_create_conjured_svalue
(m_base_region->get_type (), call, m_base_region, p);
- bind (mgr, m_base_region, sval);
+ bind (mgr, m_base_region, sval);
+ }
m_touched = true;
}
@@ -2742,6 +2756,10 @@ store::purge_region (store_manager *mgr, const region *reg)
void
store::fill_region (store_manager *mgr, const region *reg, const svalue *sval)
{
+ /* Filling an empty region is a no-op. */
+ if (reg->empty_p ())
+ return;
+
const region *base_reg = reg->get_base_region ();
if (base_reg->symbolic_for_unknown_ptr_p ()
|| !base_reg->tracked_p ())
@@ -356,8 +356,8 @@ struct byte_range
byte_size_t m_size_in_bytes;
};
-/* Concrete subclass of binding_key, for describing a concrete range of
- bits within the binding_map (e.g. "bits 8-15"). */
+/* Concrete subclass of binding_key, for describing a non-empty
+ concrete range of bits within the binding_map (e.g. "bits 8-15"). */
class concrete_binding : public binding_key
{
@@ -367,7 +367,9 @@ public:
concrete_binding (bit_offset_t start_bit_offset, bit_size_t size_in_bits)
: m_bit_range (start_bit_offset, size_in_bits)
- {}
+ {
+ gcc_assert (!m_bit_range.empty_p ());
+ }
bool concrete_p () const final override { return true; }
hashval_t hash () const
new file mode 100644
@@ -0,0 +1,8 @@
+void
+foo (int *x, int y)
+{
+ int *a = x, *b = (int *) &a;
+
+ __builtin_memcpy (b + 1, x, y);
+ foo (a, 0);
+}