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

David Holmes dholmes at openjdk.org
Tue Jan 6 02:47:09 UTC 2026


On Fri, 2 Jan 2026 07:18:06 GMT, Kim Barrett <kbarrett at openjdk.org> wrote:

> 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

Fix seems trivially fine.

Removal of the assertion sounds reasonable based on your explanation

Thanks

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

Marked as reviewed by dholmes (Reviewer).

PR Review: https://git.openjdk.org/jdk/pull/29016#pullrequestreview-3629124068


More information about the hotspot-runtime-dev mailing list