RFR: 8335298: Fix -Wzero-as-null-pointer-constant warning in G1CardSetContainers

Kim Barrett kbarrett at openjdk.org
Tue Jul 2 07:25:19 UTC 2024


On Tue, 2 Jul 2024 06:29:07 GMT, Kim Barrett <kbarrett at openjdk.org> wrote:

>> src/hotspot/share/gc/g1/g1CardSetContainers.hpp line 96:
>> 
>>> 94:     static_assert(G1CardSet::ContainerInlinePtr == 0, "unnecessary warning dodge");
>>> 95:     auto value = G1CardSet::ContainerInlinePtr;
>>> 96:     return reinterpret_cast<ContainerPtr>(value);
>> 
>> `reinterpret_cast<ContainerPtr>(G1CardSet::ContainerInlinePtr);` doesn't trigger a warning for Clang. I wonder if this is a bug in gcc.
>
> gcc treats a named constant zero as a null pointer constant.  C++14 restricts that to integer literal zeros.
> C++03 and C++11 included non-literals.  DR903 was where the change was made, and C++14 C.2.2
> suggests that DR was supposed to apply to C++11 too, even though not in the published text.  I've found
> some related gcc bugs, but not about exactly this warning.
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52145
> So yeah, it's probably a gcc bug that this triggers the warning.  I think that doesn't affect the chosen
> workaround for the warning, but maybe I should augment the comment to discuss this.
> https://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#903

There is already a gcc bug about this: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114573
I'll update the comment to refer to it.  Hopefully there aren't too many more like this in our code, or I'm going
to suggest punting on trying to enable the warning until that bug is fixed.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/19955#discussion_r1661972728


More information about the hotspot-gc-dev mailing list