<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=http://email.email.llvm.org/c/eJztV0tv4zYQ_jXyhbAhUU8ffHDsBA2w2y1aA92bQUm0xZaWVJLKo7--M9TDVqQEi26BXlaRHZMz882DM-QwrfLXjUN9eMme60yJ2oiqdNy9425_L3hJTMHJSVbMkCcmG06EJpKpM1dAYSV5_PkQBcfP268O3VnejGlDTqq6dFKmIsejKI1HE5R9VlV5JqIkTF2igGzrWoKMZDDp-SsX_sih4IqTZ7CCxoaknOgmK0janDXKWR2W3yr5qbrwVPFnIuXThdQs-5OdOSFO5A6UlvuJKw2edVqA3vrYfbcR2N1ydpTI7V47vLV3jEgcmtj5pee76Addr3zXoetW8IAxM46_bR1fMgRa5kw9i5J6K7rqFBwKxVlOLlXOJXLXlRYvLemx1IZJyfO9UEhy6AOaIzKGS6Zh-DUDsRVAw-9dVRpeGpze8ycuq5or-H2oKpkVTFz59_zEGmlWL5npaUBqNHKnYj4Mo6j9ymtV5U0GcQG4EUMvlTn0Dt9eTJSZbHJOHH8nKm3A5Yvj38-RswszxZVmv7XJwX94e1EaEXSPmQoCs8MXkm2OK-faYKL2GXnssxrWiThxZyCBZyJtBxoiql6JRnzEQjnHvxETJ2J1TwHxOR6bQa-51ODfvtfv7wikkP9Alv3EtiWN4PGBFVJQDacTrGd4R7CunHA_y-bQLcmtlsEdXuZoYCs_MR-fvBqPJ17gs1ySfCJpuem21ehQ6nrUD8IoTtYwQFutzzQknjtrMj4tywMieO6Ew4n35LkQktsot7we8rqzrnSrMQrx3Lp8q0fxEj5zRr1RWxoiYev8OPBkTmFnMebWSuXADCPgXUIF6LoxpSViBlt89KX1fxjOuWbRNDewfRg-Kg0ovmPKNG9HKctTMc3piY-jgeKmUWVbWb3UwPDf1WvzvxQsa-D4GlXqj3L8jnL8URejujD8UktUDcecZFqTx9IcXmuOfrQTD9hC2an-BMQYHmxVJBO_MugCDH-pFUGPRGYD_tvn7adPR2jTbNjdF2_kA64tfSCQDvfQjUGyd01bZwUr87ahS6GxQjIiWuKAMJjYih77zfZmiWUORoHBrVVHBASXR77RZLATwwyqo-BtvLvooA03WoaYjRBIu68gyhD8CRA6dRyjjU3ssa2BN-7NbyI3SG3yjfFn03CIUVY1pjcayvOKVVaG8L8aJjXG_9qNX5cF16TVEO7KqzrbIdIe89ZNu-OO0xg2BEw6wDxaq-cgJuHqjSUoe3NHeCM3zgs7dVv9cpyQtzXEpebfHrNfsGIM1gbEAT2axZ1UqPteeWJcL7YbnpaaLUF_d-0jhxC0yfI2Qz7QNe6ss-pS44b6LEyBt5jll3e67vuXmmfGtv7kS2NgE5zFuwZlto9vsbaZgQT7CObf5eNYFNPCS4IgioPAjf3YXYehF3nRO5m3ptT3Y-r6URIGcRwmbjyXaN7KQkJ53Xnrjy4r9nuRb_x87a_ZAo72olIbxcu_RcrFolFyUxhTa8wtuyueYQmadAUrAgO8Xnb_lnDd-QNiD0OhdcPxJhX6NAkWxYb6iZ-ektQLQ5-zMKL5iWUsPIVr10uDgC8kSyGrN3D8wpG7-H6VYkNdPNq9tRsFkZes3GRNE-5GbhKcklMYOIHLIYvlCnFWlTov1MZC4oUaiFJoo69ESBdxLjnvLTTCSL6ZXNYx8tP7fZsDzXlhjdxYC_8BY2Z8GQ>53284</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            arm64 Apple clang: float to __int128 cast bug
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          renzibei
      </td>
    </tr>
</table>

<pre>
    ## Description
When the float value is larger than INT64_MAX, the cast from float to __int128 is wrong in arm64 Apple clang 13.0.0. There won't be such bugs in the clang from Homebrew llvm package  `Homebrew clang version 13.0.0`

## Clang version
```
Apple clang version 13.0.0 (clang-1300.0.29.30)
Target: arm64-apple-darwin21.2.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
```

## Reproduce code

```c++
#include <iostream>
#include <cmath>

std::ostream& operator<<( std::ostream& dest, __int128_t value ) {
    std::ostream::sentry s( dest );
    if ( s ) {
        __uint128_t tmp = value < 0 ? -value : value;
        char buffer[ 128 ];
        char* d = std::end( buffer );
        do
        {
            -- d;
            *d = "0123456789"[ tmp % 10 ];
            tmp /= 10;
        } while ( tmp != 0 );
        if ( value < 0 ) {
            -- d;
            *d = '-';
        }
        int len = std::end( buffer ) - d;
        if ( dest.rdbuf()->sputn( d, len ) != len ) {
            dest.setstate( std::ios_base::badbit );
        }
    }
    return dest;
}

std::ostream& operator<<( std::ostream& dest, __uint128_t value ) {
    std::ostream::sentry s( dest );
    if ( s ) {
        auto tmp = value;
        char buffer[ 128 ];
        char* d = std::end( buffer );
        do
        {
            -- d;
            *d = "0123456789"[ tmp % 10 ];
            tmp /= 10;
        } while ( tmp != 0 );
        int len = std::end( buffer ) - d;
        if ( dest.rdbuf()->sputn( d, len ) != len ) {
            dest.setstate( std::ios_base::badbit );
        }
    }
    return dest;
}

template<class IntType, class FloatType>
int Test() {
    constexpr static int SMALL_INT = 0x1;
    // 2^64 to float type, and cast back to int type
    FloatType float_value = std::ldexp(static_cast<FloatType>(SMALL_INT), 64);
    IntType int_value = IntType(SMALL_INT) << 64;

    IntType back_int_value = static_cast<IntType>(float_value);
    if (int_value != back_int_value) {
        std::cout << "int_value not equals to the float cast back int value\nint_value: " << int_value <<
        ", cast_back_value: " << back_int_value << " , float value: " << float_value << std::endl;
    }
    else {
        std::cout << "Pass test\n";
    }

    return 0;
}

int main() {
    Test<__int128_t, float>();
    return 0;
}
```
compile with `-O0`

## Expectation Output
```
Pass test
```
## Actual Output
```
int_value not equals to the float cast back int value
int_value: 18446744073709551616, cast_back_value: 9223372036854775807 , float value: 1.84467e+19
```



</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJztV0uP2zYQ_jXyhbBBUe-DD147iwZ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