RFR: JDK-8294902: Undefined Behavior in C2 regalloc with null references [v6]

Andrew Haley aph at openjdk.org
Mon Dec 12 14:51:25 UTC 2022


On Mon, 5 Dec 2022 21:15:47 GMT, Kim Barrett <kbarrett at openjdk.org> wrote:

>> Andrew Haley has updated the pull request incrementally with one additional commit since the last revision:
>> 
>>   Feedback from reviewers
>
> src/hotspot/share/runtime/vmStructs.hpp line 193:
> 
>> 191: #define CHECK_NONSTATIC_VM_STRUCT_ENTRY(typeName, fieldName, type) {               \
>> 192:     char space[sizeof (typeName)];                                                 \
>> 193:     typeName *dummyObj = (typeName *)space; type* dummy = &dummyObj->fieldName;    \
> 
> The member value type checking could be written more explicitly (and IMO more
> clearly, though metaprogramming :) ) as:
> 
> 
> #define CHECK_NONSTATIC_VM_STRUCT_ENTRY(typeName, fieldName, type) { \
>   std::static_assert( \
>     std::is_convertible< \
>       std::add_pointer_t<decltype(std::declval<typeName>().fieldName)>, \
>       std::add_pointer_t<type>>::value, \
>     "type mismatch for " XSTR(fieldName) " member of " XSTR(typeName)); \
>   assert(offset_of(typeName, fieldName) < sizeof(typeName), "..."); \
> }
> 
> 
> except that uses `std::declval`, which is in `<utility>`, which is not (yet)
> permitted for use in HotSpot code.  Maybe that will change someday.  In the
> meantime, we could add our own definition to globalUtilities.hpp, since it is
> quite trivial.
> 
> 
> template<typename T>
> std::add_rvalue_reference_t<T> declval() noexcept;
> 
> 
> I tried using `std::is_same` instead of `std::is_convertible`, which seems
> like it might be better. However, there were a number of failures because some
> uses are not exact matches. There were differences in volatile, in base vs
> derived types, and reference vs non-reference types (if you drop the
> conversion to pointers).
> 
> This dodges the whole question of alignment of the space buffer.

Done.

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

PR: https://git.openjdk.org/jdk/pull/10920


More information about the hotspot-dev mailing list