RFR: 8340620: Fix -Wzero-as-null-pointer-constant warnings for CompressedOops
Aleksey Shipilev
shade at openjdk.org
Thu Sep 26 08:25:34 UTC 2024
On Wed, 25 Sep 2024 20:55:45 GMT, Kim Barrett <kbarrett at openjdk.org> wrote:
>> 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.
>
> Correct that static_assert can't be used, because of the reinterpret_cast.
>
> I considered putting the assert in CompressedOops::set_base, with comments to
> connect encode/decode with that assertion, but prefer putting the assert near
> the code that is actually relying on the property. Even with -O0 gcc seems to
> constant fold the expression and (pretty much?) compile away the assertion.
>
> A null pointer value is not guaranteed to have a zero representation. The
> conversion of a literal 0 to a null pointer value is syntactic sugar. The
> bit pattern of the result might be something else. There's some good
> discussion of this here:
> https://stackoverflow.com/questions/2761360/could-i-ever-want-to-access-the-address-zero
All right, if this assert folds, this all is just nitpicking then. Ship it.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/21172#discussion_r1776607757
More information about the hotspot-dev
mailing list