RFR: 8357579: Compilation error: first argument in call to 'memset' is a pointer to non-trivially copyable type [v13]
Ashutosh Mehra
asmehra at openjdk.org
Mon Nov 10 15:07:03 UTC 2025
On Mon, 10 Nov 2025 07:24:50 GMT, Jan Kratochvil <jkratochvil at openjdk.org> wrote:
>> With clang-20 using --with-toolchain-type=clang resolveFieldEntry.cpp and resolveMethodEntry.cpp break the build with similar warnings like:
>>
>> src/hotspot/share/oops/resolvedFieldEntry.cpp:49:10: error: first argument in call to 'memset' is a pointer to non-trivially copyable type 'ResolvedFieldEntry' [-Werror,-Wnontrivial-memcall]
>> 49 | memset(this, 0, sizeof(*this));
>> | ^
>> src/hotspot/share/oops/resolvedFieldEntry.cpp:49:10: note: explicitly cast the pointer to silence this warning
>> 49 | memset(this, 0, sizeof(*this));
>> | ^
>> | (void*)
>>
>> The patch follows the suggested fix.
>
> Jan Kratochvil has updated the pull request incrementally with one additional commit since the last revision:
>
> Add Ioi Lam's comment
src/hotspot/share/oops/resolvedFieldEntry.cpp line 31:
> 29: STATIC_ASSERT(std::is_trivially_copyable_v<ResolvedFieldEntry> == true);
> 30:
> 31: // Detect inadvertently introduced trailing padding.
Another way to detect padding (trailing or internal) could be to compare sizeof(ResolvedFieldEntry) against the sum up the size of all the elements. Something like:
`sizeofResolvedFieldEntry) == (sizeof(InstanceKlass*) + sizeof(int) + sizeof(u2) + ... + sizeof(_padding))`
It looks cumbersome but I think it is easy enough to update if a new field is added because the static assert will fail immediately.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/26098#discussion_r2510917443
More information about the hotspot-dev
mailing list