https://gcc.gnu.org/g:a171c89fbf6720bf8562b2e0121e582fbadd5e50
commit r17-712-ga171c89fbf6720bf8562b2e0121e582fbadd5e50 Author: Richard Sandiford <[email protected]> Date: Mon May 25 08:04:11 2026 +0100 bitmap: Fix bitmap_last_set_bit 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. Diff: --- gcc/bitmap.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gcc/bitmap.cc b/gcc/bitmap.cc index 4ba78e8bf900..3c9db885a353 100644 --- a/gcc/bitmap.cc +++ b/gcc/bitmap.cc @@ -1329,13 +1329,13 @@ bitmap_last_set_bit (const_bitmap a) 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
