]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
bitmap: Fix bitmap_last_set_bit
authorRichard Sandiford <rdsandiford@googlemail.com>
Mon, 25 May 2026 07:04:11 +0000 (08:04 +0100)
committerRichard Sandiford <rdsandiford@googlemail.com>
Mon, 25 May 2026 07:04:11 +0000 (08:04 +0100)
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.

gcc/bitmap.cc

index 4ba78e8bf90081b90097e49e104faf56ad043c7e..3c9db885a35377ea6620a77e1ea66495f002382c 100644 (file)
@@ -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