RFR: 8356865: C2: Unreasonable values for debug flag FastAllocateSizeLimit can lead to left-shift-overflow, which is UB [v2]
Evgeny Astigeevich
eastigeevich at openjdk.org
Wed Jun 18 19:44:27 UTC 2025
On Wed, 18 Jun 2025 07:35:47 GMT, Benoît Maillard <bmaillard at openjdk.org> wrote:
>> Yes we use -std=c++14, but creating a negative value in this way still feels like a kind of overflow to me.
>
> Thanks for the comments!
>
> I added the assert because the issue in the JBS mentioned a specific case where we ended up with negative values.
>
> Should I leave it like this, or rather convert it to a more specific check (ie. making sure that the `LogBytesPerLong - log2_esize` most significant bits are not used **before** shifting)?
IMO your assert is obfuscating the overflow problem.
I think the assert should be before doing the shift.
It can be like:
assert((fast_size_limit == 0) || (count_leading_zeros(fast_size_limit) > (LogBytesPerLong - log2_esize), "fast_size_limit (%d) overflow when shifted left by %d", fast_size_limit, (LogBytesPerLong - log2_esize));
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/25834#discussion_r2155369775
More information about the hotspot-dev
mailing list