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

Kim Barrett kbarrett at openjdk.org
Tue Jan 6 15:06:45 UTC 2026


On Tue, 6 Jan 2026 02:43:41 GMT, David Holmes <dholmes 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

Thanks for reviewing @dholmes-ora

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

PR Comment: https://git.openjdk.org/jdk/pull/29016#issuecomment-3715047709


More information about the hotspot-runtime-dev mailing list