JDK-8357579 : Compilation error: first argument in call to 'memset' is a pointer to non-trivially copyable type
  • Type: Bug
  • Component: hotspot
  • Sub-Component: runtime
  • Affected Version: 25
  • Priority: P3
  • Status: Open
  • Resolution: Unresolved
  • OS: generic
  • CPU: generic
  • Submitted: 2025-05-21
  • Updated: 2025-06-09
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 26
26Unresolved
Related Reports
Causes :  
Description
ADDITIONAL SYSTEM INFORMATION :
clang 20 on Linux

A DESCRIPTION OF THE PROBLEM :
With clang 20, resolveFieldEntry.cpp and resolveMethodEntry.cpp break the build with similar warnings:

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*)
src/hotspot/share/oops/resolvedMethodEntry.cpp:43:12: error: first argument in call to 'memset' is a pointer to non-trivially copyable type 'ResolvedMethodEntry' [-Werror,-Wnontrivial-memcall]
   43 | memset(this, 0, sizeof(*this));
      | ^
src/hotspot/share/oops/resolvedMethodEntry.cpp:43:12: note: explicitly cast the pointer to silence this warning
   43 | memset(this, 0, sizeof(*this));
      | ^
      | (void*)
XXXX/src/hotspot/share/oops/resolvedMethodEntry.cpp:48:12: error: first argument in call to 'memset' is a pointer to non-trivially copyable type 'ResolvedMethodEntry' [-Werror,-Wnontrivial-memcall]
   48 | memset(this, 0, sizeof(*this));
      | ^
XXXX/src/hotspot/share/oops/resolvedMethodEntry.cpp:48:12: note: explicitly cast the pointer to silence this warning
   48 | memset(this, 0, sizeof(*this));
      | ^
      | (void*)


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Build with --with-toolchain-type=clang when clang is version 20.
Comments
The warning is obviously correct; the class involved is not trivially copyable. The first thing I wondered, is why is the class not trivially copyable. It defines a private helper `copy_from` (which just does member-by-member copying, so what default copyiers are spedified to do) and has the copy ctor and assignment operators call it. So why don't we just use the default copy ctor and assignment operator? That is, why isn't remove_unshareable_info something like ``` *this = ResolvedFieldEntry(_cpool_index); ``` with no `memset` at all? Maybe there is some issue with padding vs reproducible builds? But I can't find any discussion of that, either in code comments or in the review of JDK-8293980 (which added `copy_from`). I found no explanation at all for the introduction of `copy_from`. And without more information, it's hard to suggest alternatives.
23-05-2025