Commit 8240d003 by Martin Liska

Add gcc_checking_assert for sbitmap.c.

From-SVN: r253825
parent a584b03d
......@@ -180,6 +180,8 @@ sbitmap_vector_alloc (unsigned int n_vecs, unsigned int n_elms)
void
bitmap_copy (sbitmap dst, const_sbitmap src)
{
gcc_checking_assert (src->size <= dst->size);
memcpy (dst->elms, src->elms, sizeof (SBITMAP_ELT_TYPE) * dst->size);
}
......@@ -187,6 +189,8 @@ bitmap_copy (sbitmap dst, const_sbitmap src)
int
bitmap_equal_p (const_sbitmap a, const_sbitmap b)
{
bitmap_check_sizes (a, b);
return !memcmp (a->elms, b->elms, sizeof (SBITMAP_ELT_TYPE) * a->size);
}
......@@ -211,6 +215,8 @@ bitmap_clear_range (sbitmap bmap, unsigned int start, unsigned int count)
if (count == 0)
return;
bitmap_check_index (bmap, start + count - 1);
unsigned int start_word = start / SBITMAP_ELT_BITS;
unsigned int start_bitno = start % SBITMAP_ELT_BITS;
......@@ -267,6 +273,8 @@ bitmap_set_range (sbitmap bmap, unsigned int start, unsigned int count)
if (count == 0)
return;
bitmap_check_index (bmap, start + count - 1);
unsigned int start_word = start / SBITMAP_ELT_BITS;
unsigned int start_bitno = start % SBITMAP_ELT_BITS;
......@@ -324,6 +332,8 @@ bool
bitmap_bit_in_range_p (const_sbitmap bmap, unsigned int start, unsigned int end)
{
gcc_checking_assert (start <= end);
bitmap_check_index (bmap, end);
unsigned int start_word = start / SBITMAP_ELT_BITS;
unsigned int start_bitno = start % SBITMAP_ELT_BITS;
......@@ -467,6 +477,9 @@ bitmap_vector_ones (sbitmap *bmap, unsigned int n_vecs)
bool
bitmap_ior_and_compl (sbitmap dst, const_sbitmap a, const_sbitmap b, const_sbitmap c)
{
bitmap_check_sizes (a, b);
bitmap_check_sizes (b, c);
unsigned int i, n = dst->size;
sbitmap_ptr dstp = dst->elms;
const_sbitmap_ptr ap = a->elms;
......@@ -489,6 +502,8 @@ bitmap_ior_and_compl (sbitmap dst, const_sbitmap a, const_sbitmap b, const_sbitm
void
bitmap_not (sbitmap dst, const_sbitmap src)
{
bitmap_check_sizes (src, dst);
unsigned int i, n = dst->size;
sbitmap_ptr dstp = dst->elms;
const_sbitmap_ptr srcp = src->elms;
......@@ -510,6 +525,9 @@ bitmap_not (sbitmap dst, const_sbitmap src)
void
bitmap_and_compl (sbitmap dst, const_sbitmap a, const_sbitmap b)
{
bitmap_check_sizes (a, b);
bitmap_check_sizes (b, dst);
unsigned int i, dst_size = dst->size;
unsigned int min_size = dst->size;
sbitmap_ptr dstp = dst->elms;
......@@ -537,6 +555,8 @@ bitmap_and_compl (sbitmap dst, const_sbitmap a, const_sbitmap b)
bool
bitmap_intersect_p (const_sbitmap a, const_sbitmap b)
{
bitmap_check_sizes (a, b);
const_sbitmap_ptr ap = a->elms;
const_sbitmap_ptr bp = b->elms;
unsigned int i, n;
......@@ -555,6 +575,9 @@ bitmap_intersect_p (const_sbitmap a, const_sbitmap b)
bool
bitmap_and (sbitmap dst, const_sbitmap a, const_sbitmap b)
{
bitmap_check_sizes (a, b);
bitmap_check_sizes (b, dst);
unsigned int i, n = dst->size;
sbitmap_ptr dstp = dst->elms;
const_sbitmap_ptr ap = a->elms;
......@@ -577,6 +600,9 @@ bitmap_and (sbitmap dst, const_sbitmap a, const_sbitmap b)
bool
bitmap_xor (sbitmap dst, const_sbitmap a, const_sbitmap b)
{
bitmap_check_sizes (a, b);
bitmap_check_sizes (b, dst);
unsigned int i, n = dst->size;
sbitmap_ptr dstp = dst->elms;
const_sbitmap_ptr ap = a->elms;
......@@ -599,6 +625,9 @@ bitmap_xor (sbitmap dst, const_sbitmap a, const_sbitmap b)
bool
bitmap_ior (sbitmap dst, const_sbitmap a, const_sbitmap b)
{
bitmap_check_sizes (a, b);
bitmap_check_sizes (b, dst);
unsigned int i, n = dst->size;
sbitmap_ptr dstp = dst->elms;
const_sbitmap_ptr ap = a->elms;
......@@ -620,6 +649,8 @@ bitmap_ior (sbitmap dst, const_sbitmap a, const_sbitmap b)
bool
bitmap_subset_p (const_sbitmap a, const_sbitmap b)
{
bitmap_check_sizes (a, b);
unsigned int i, n = a->size;
const_sbitmap_ptr ap, bp;
......@@ -636,6 +667,10 @@ bitmap_subset_p (const_sbitmap a, const_sbitmap b)
bool
bitmap_or_and (sbitmap dst, const_sbitmap a, const_sbitmap b, const_sbitmap c)
{
bitmap_check_sizes (a, b);
bitmap_check_sizes (b, c);
bitmap_check_sizes (c, dst);
unsigned int i, n = dst->size;
sbitmap_ptr dstp = dst->elms;
const_sbitmap_ptr ap = a->elms;
......@@ -659,6 +694,10 @@ bitmap_or_and (sbitmap dst, const_sbitmap a, const_sbitmap b, const_sbitmap c)
bool
bitmap_and_or (sbitmap dst, const_sbitmap a, const_sbitmap b, const_sbitmap c)
{
bitmap_check_sizes (a, b);
bitmap_check_sizes (b, c);
bitmap_check_sizes (c, dst);
unsigned int i, n = dst->size;
sbitmap_ptr dstp = dst->elms;
const_sbitmap_ptr ap = a->elms;
......
......@@ -96,10 +96,29 @@ struct simple_bitmap_def
/* Return the number of bits in BITMAP. */
#define SBITMAP_SIZE(BITMAP) ((BITMAP)->n_bits)
/* Verify that access at INDEX in bitmap MAP is valid. */
static inline void
bitmap_check_index (const_sbitmap map, int index)
{
gcc_checking_assert (index >= 0);
gcc_checking_assert ((unsigned int)index < map->n_bits);
}
/* Verify that bitmaps A and B have same size. */
static inline void
bitmap_check_sizes (const_sbitmap a, const_sbitmap b)
{
gcc_checking_assert (a->n_bits == b->n_bits);
}
/* Test if bit number bitno in the bitmap is set. */
static inline SBITMAP_ELT_TYPE
bitmap_bit_p (const_sbitmap map, int bitno)
{
bitmap_check_index (map, bitno);
size_t i = bitno / SBITMAP_ELT_BITS;
unsigned int s = bitno % SBITMAP_ELT_BITS;
return (map->elms[i] >> s) & (SBITMAP_ELT_TYPE) 1;
......@@ -110,6 +129,8 @@ bitmap_bit_p (const_sbitmap map, int bitno)
static inline void
bitmap_set_bit (sbitmap map, int bitno)
{
bitmap_check_index (map, bitno);
map->elms[bitno / SBITMAP_ELT_BITS]
|= (SBITMAP_ELT_TYPE) 1 << (bitno) % SBITMAP_ELT_BITS;
}
......@@ -119,6 +140,8 @@ bitmap_set_bit (sbitmap map, int bitno)
static inline void
bitmap_clear_bit (sbitmap map, int bitno)
{
bitmap_check_index (map, bitno);
map->elms[bitno / SBITMAP_ELT_BITS]
&= ~((SBITMAP_ELT_TYPE) 1 << (bitno) % SBITMAP_ELT_BITS);
}
......@@ -148,6 +171,8 @@ static inline void
bmp_iter_set_init (sbitmap_iterator *i, const_sbitmap bmp,
unsigned int min, unsigned *bit_no ATTRIBUTE_UNUSED)
{
bitmap_check_index (bmp, min);
i->word_num = min / (unsigned int) SBITMAP_ELT_BITS;
i->bit_num = min;
i->size = bmp->size;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment