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

Kim Barrett kbarrett at openjdk.org
Fri Dec 13 17:27:44 UTC 2024


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.

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

Commit messages:
 - fix some casts of literal 0

Changes: https://git.openjdk.org/jdk/pull/22740/files
  Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=22740&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8346160
  Stats: 6 lines in 5 files changed: 0 ins; 0 del; 6 mod
  Patch: https://git.openjdk.org/jdk/pull/22740.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/22740/head:pull/22740

PR: https://git.openjdk.org/jdk/pull/22740


More information about the hotspot-dev mailing list