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

--- Comment #3 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jakub Jelinek <[email protected]>:

https://gcc.gnu.org/g:b20d26da1d10536fd3e5448f6b467f62ecdb4e73

commit r17-6775-gb20d26da1d10536fd3e5448f6b467f62ecdb4e73
Author: Jakub Jelinek <[email protected]>
Date:   Sat Nov 28 10:15:18 2026 +0100

    expmed: Avoid compiler UB [PR129091]

    This code computes a mask in two spots, but when thissize is 63
    where it should compute HOST_WIDE_INT_C (0x7fffffffffffffff) mask,
    it invokes UB (for pre-C++23 already maybe on the left shift, I forgot
    the C++20 and earlier rule, for C++23 and later on the subtraction,
    because 1L << 63 is LONG_MIN and subtracting one from it is overflows.

    Fixed by using HOST_WIDE_INT_1U instead, GEN_INT works fine with
    both HOST_WIDE_INT and unsigned HOST_WIDE_INT and in these cases
    as other & operand is unsigned HOST_WIDE_INT it doesn't change
    anything except remove UB.

    2026-11-28  Jakub Jelinek  <[email protected]>

            PR middle-end/129091
            * expmed.cc (store_split_bit_field): Use HOST_WIDE_INT_1U
            instead of HOST_WIDE_INT_1 in 2 left shifts.

            * gcc.dg/pr129091.c: New test.

    Reviewed-by: Andrea Pinski <[email protected]>

Reply via email to