RFR: 8374446: Fix -Wzero-as-null-pointer-constant warnings in test_compressedKlass.cpp

Kim Barrett kbarrett at openjdk.org
Fri Jan 2 07:26:08 UTC 2026


Please review this simple change to a recently added gtest to avoid triggering
-Wzero-as-null-pointer-constant warnings when that warning is enabled.

There are two parts to the change. One is just an obvious replacement of 0
with nullptr.

The other is the removal of a gtest assertion. That assertion's predicate is
attempting to verify the CompressedKlassPointers state has been initialized.
But the test being used (null pointer <= base pointer) is technically invalid;
ordered comparisons between a pointer and null are UB. And even ignoring that,
the compiler may decide the comparison is tautologially true, or it may always
be true at runtime, because pointer comparison is treated as unsigned by at
least some compilers. It would be better done via an is_initialized() function
in CompressedKlassPointers, or use == with the initial "uninitialized" value
of -1. But we're already asserting initialization in the implementation of the
base() function, so at least in debug builds we've already verified
initialization. It doesn't seem worthwhile adding is_initialized() or breaking
through the abstraction and using -1.

Testing: mach5 tier1

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

Commit messages:
 - fix -Wzero-as-null-pointer-constant warnings in test_compressedKlass.cpp

Changes: https://git.openjdk.org/jdk/pull/29016/files
  Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=29016&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8374446
  Stats: 3 lines in 1 file changed: 0 ins; 1 del; 2 mod
  Patch: https://git.openjdk.org/jdk/pull/29016.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/29016/head:pull/29016

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


More information about the hotspot-runtime-dev mailing list