RFR: JDK-8299688: Adopt C++14 compatible std::bit_cast introduced in C++20 [v4]
Justin King
jcking at openjdk.org
Mon Jan 23 19:11:07 UTC 2023
On Mon, 23 Jan 2023 11:01:48 GMT, Julian Waters <jwaters at openjdk.org> wrote:
>> src/hotspot/share/utilities/bitCast.hpp line 54:
>>
>>> 52: constexpr To bit_cast(const From& from) {
>>> 53: #if HAS_BUILTIN(__builtin_bit_cast) && !defined(__APPLE__)
>>> 54: return __builtin_bit_cast(To, from);
>>
>> Throughout, I see no good reason to uglify the code with platform-specific conditional code
>> when the portable version is just fine. And then the supporting infrastructure to define that
>> macro isn't needed. The `!defined(__APPLE__)` makes this seem particularly problematic.
>> Is the new `HAS_BUILTIN` just broken? Or is `__builtin_bit_cast` broken for Macs? Or what?
>
> I also don't like the direct call to __builtins either, gcc to my knowledge automatically replaces the appropriate builtins when optimization is specified
Apple Clang seemed to have a bug with the version we are using in GHA. I bumped them to 12.5.1 and the error disappeared.
`__builtin_bit_cast` is used to implement std::bit_cast for Clang/GCC. It is purely a compiler construct IIRC and has no runtime function equivalent. It's always replaced with machine code for performing a byte-wise copy and ensures no shenanigans occur. Additionally std::bit_cast is the only way to convert between floating point and integral without invoking undefined behavior, though the union trick does currently work. The other option is std::memcpy.
-------------
PR: https://git.openjdk.org/jdk/pull/11865
More information about the hotspot-dev
mailing list