RFR: 8332697: ubsan: shenandoahSimpleBitMap.inline.hpp:68:23: runtime error: signed integer overflow: -9223372036854775808 - 1 cannot be represented in type 'long int'
Andrew Haley
aph at openjdk.org
Sun Jul 21 08:18:37 UTC 2024
On Fri, 19 Jul 2024 22:41:11 GMT, Dean Long <dlong at openjdk.org> wrote:
>> Cast the result of `nth_bit(n)` to `uintptr_t` to prevent signed integer overflow error reported by `ubsan`. Unsigned overflow is not undefined behavior and is not checked by `ubsan`.
>
> src/hotspot/share/utilities/globalDefinitions.hpp line 1069:
>
>> 1067: // (note: #define used only so that they can be used in enum constant definitions)
>> 1068: #define nth_bit(n) (((n) >= BitsPerWord) ? 0 : (OneBit << (n)))
>> 1069: #define right_n_bits(n) ((uintptr_t) nth_bit(n) - 1)
>
> This changes the return type of right_n_bits, which could break existing code. If we need an unsigned version, I think it should have a different name.
And this is at best a partial fix: `OneBit << 63` overflows.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/20164#discussion_r1685678905
More information about the hotspot-dev
mailing list