RFR: 8346160: Fix -Wzero-as-null-pointer-constant warnings from explicit casts

Kim Barrett kbarrett at openjdk.org
Mon Dec 16 04:27:39 UTC 2024


On Fri, 13 Dec 2024 17:39:19 GMT, Stefan Karlsson <stefank at openjdk.org> wrote:

>> Please review this change that removes -Wzero-as-null-pointer-constant
>> warnings from explicit casts of a literal 0 to a pointer type.  Different
>> versions of gcc seem to warn about different cases changed here, but all of
>> these showed up as a warning in some testing, whether Oracle CI, GHA sanity
>> tests, or local cross-builds using Oracle's devkits for that.
>> 
>> Some of the changes simply replace a cast of 0 with nullptr.
>> 
>> The UNIX_PATH_MAX macro definitions in attachListener_{aix,posix}.cpp is
>> changed to use a C++11 feature for obtaining the size of a non-static data
>> member without requiring an instance.
>> https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2253.html
>> I guess I need to propose an update to the style guide to mention this feature.
>> 
>> In CompressedKlassPointers::initialize, casting
>> CompressedClassSpaceBaseAddress to a pointer type was triggering the warning
>> in release builds for some reason. That's not a literal 0, even though it *is*
>> a constant 0 in a release build. Changed to avoid that cast rather than trying
>> to argue with some versions of the compiler.
>> 
>> Although different gcc versions on different platforms seemed to vary whether
>> warning about each of these, this actually seems to be all of the explict
>> casts of a literal 0 to a pointer in HotSpot.  Though because of the varied
>> behaviors, new ones might slip in later.
>> 
>> Testing: mach5 tier1, GHA sanity tests, both with and without the warning enabled.
>
> Marked as reviewed by stefank (Reviewer).

Thanks for reviews @stefank and @dholmes-ora

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

PR Comment: https://git.openjdk.org/jdk/pull/22740#issuecomment-2544564921


More information about the hotspot-dev mailing list