If the last bit in a bitmap was in elt->bits[0], bitmap_last_set_bit
would not read it and would instead fall through with "word" still set
to elt->bits[1], which is known to be 0.
This patch fixes it to use the same structure as
bitmap_first_set_bit_worker.
As you might expect from this, only the sbitmap version of this
function appears to be used.
gcc/
* bitmap.cc (bitmap_last_set_bit): Fix handling of index 0.
elt = elt->next;
bit_no = elt->indx * BITMAP_ELEMENT_ALL_BITS;
- for (ix = BITMAP_ELEMENT_WORDS - 1; ix >= 1; ix--)
+ for (ix = BITMAP_ELEMENT_WORDS - 1; ix >= 0; ix--)
{
word = elt->bits[ix];
if (word)
goto found_bit;
}
- gcc_assert (elt->bits[ix] != 0);
+ gcc_unreachable ();
found_bit:
bit_no += ix * BITMAP_WORD_BITS;
#if GCC_VERSION >= 3004