RFR: 8309685: Fix -Wconversion warnings in assembler and register code [v2]
Coleen Phillimore
coleenp at openjdk.org
Wed Jun 14 12:27:58 UTC 2023
On Tue, 13 Jun 2023 18:35:20 GMT, Coleen Phillimore <coleenp at openjdk.org> wrote:
>> Taking out the ENABLE_IF<is_integral> at least allows it to compile but there are lots of crashes because of sign extension.
>>
>> Maybe we can make checked_cast<> tolerant of that somehow?
>>
>> ```template <typename T2, typename T1>
>> constexpr T2 checked_cast(T1 thing) {
>> T2 result = static_cast<T2>(thing);
>> assert(static_cast<T1>(result) == thing, "must be");
>> return result;
>> }```
>
> How about something like this?
>
> template<typename T, ENABLE_IF(std::is_same<T, uint8_t>::value)>
> void emit_int8(T v) { code_section()->emit_int8(v); }
>
> template<typename T, ENABLE_IF(!std::is_same<T, uint8_t>::value)>
> void emit_int8(T v) {
> if (v < 0) {
> int8_t tmp = static_cast<int8_t>(v);
> assert(static_cast<T>(v) == tmp, "signed cast preserves value");
> emit_int8(static_cast<uint8_t>(v));
> } else {
> emit_int8(checked_cast<uint8_t>(v));
> }
> }
I pushed something that I think is better.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/14396#discussion_r1229526028
More information about the hotspot-dev
mailing list