RFR: 8340620: Fix -Wzero-as-null-pointer-constant warnings for CompressedOops
Quan Anh Mai
qamai at openjdk.org
Wed Sep 25 11:25:35 UTC 2024
On Wed, 25 Sep 2024 08:36:37 GMT, Aleksey Shipilev <shade at openjdk.org> wrote:
>> src/hotspot/share/oops/compressedOops.inline.hpp line 53:
>>
>>> 51: // Assume a null base casts to zero. Otherwise we need more complexity that
>>> 52: // we can't test, since this is true for all currently supported platforms.
>>> 53: assert(0 == reinterpret_cast<uintptr_t>(nullptr), "null pointer value not zero?");
>>
>> Could this be a static_assert?
>
> +1. Although I would expect any sane compiler to fold it, maybe it is still not optimized with something like `-O0`. Or maybe just move these asserts to `CompressedOops::initialize`, so whatever happens, happens once.
This cannot be used in `static_assert` because `reinterpret_cast` is not allowed here.
I believe [`reinterpret_cast<uintptr_t>(nullptr)` will always return 0](https://en.cppreference.com/w/cpp/language/reinterpret_cast). You may need to do it the other way around.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/21172#discussion_r1775048234
More information about the hotspot-dev
mailing list