RFR: 8337418: Fix -Wzero-as-null-pointer-constant warnings in prims code
David Holmes
dholmes at openjdk.org
Tue Jul 30 07:57:32 UTC 2024
On Tue, 30 Jul 2024 07:16:21 GMT, Kim Barrett <kbarrett at openjdk.org> wrote:
>> This is value-initialization syntax. Value-initialization of a primitive type is zero-initialization.
>>
>> However, I think we don't need the local variable at all. Here and in the other 5(?) similar places, rather than
>>
>> ResultType ret{};
>> ...
>> ret = jvalue.get_##ResultType();
>> return ret;
>>
>> I think we could just have
>>
>> ...
>> return jvalue.get_##ResultType();
>
> Looks like eliminating the variable doesn't work. It gets used in a `DT_RETURN_MARK_FOR` form, which
> needs the address of the return value. That address is obtained using a reference. Taking a reference
> to an uninitialized variable is (I think) okay, so long as one doesn't attempt to use the uninitialized value.
> But then the assignment could be problematic if it's uninitialized and the assignment operator is non-trivial.
> I expect the compiler will optimize away a trivial zero initialization if it's not needed. So ensuring it is
> value-initialized seems like the cleanest thing to do.
One day I will remember what this syntax is and does.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/20385#discussion_r1696496369
More information about the hotspot-dev
mailing list