https://gcc.gnu.org/bugzilla/show_bug.cgi?id=129105

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2026-11-30
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
Confirmed. In libgcc/config/libbid/bid_from_int.c (bid64_from_int32), `x = ~x +
1` performs signed negation on `int x`, which is undefined behavior when `x ==
INT_MIN`. The compiler optimizes based on the absence of signed overflow,
assuming `x > 0`, and sign-extends with `sxtw` (AArch64) or `movslq` (x86_64).
When `x` is INT_MIN, this extends `0x80000000` to `0xffffffff80000000`, turning
the BID combination field into NaN. Similarly, in `bid128_from_int64`,
`res.w[LOW_128W] = ~x + 1;` overflows for LLONG_MIN. Performing the negation in
unsigned arithmetic (~((unsigned int) x) + 1 and ~((UINT64) x) + 1), as already
done in bid128_from_int32 and bid64_from_int64, fixes the bug.

Reply via email to