RFR: 8332697: ubsan: shenandoahSimpleBitMap.inline.hpp:68:23: runtime error: signed integer overflow: -9223372036854775808 - 1 cannot be represented in type 'long int'

Dean Long dlong at openjdk.org
Fri Jul 19 22:43:36 UTC 2024


On Fri, 12 Jul 2024 20:53:04 GMT, Henry Lin <duke 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.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/20164#discussion_r1685072633


More information about the hotspot-dev mailing list