Created
April 27, 2020 19:37
-
-
Save broadwaylamb/956866a4c6ff531b48562f3673d4d26d to your computer and use it in GitHub Desktop.
A bug in the LLVM implementation of the divtf3 builtin (aarch64-linux-gnu)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <ios> | |
#include <iomanip> | |
#include <cstdint> | |
#include <cstring> | |
#include <cassert> | |
#include <limits> | |
// If this file is compiled and linked against libgcc, it runs just fine. | |
// If it is linked against compiler-rt builtins, the assertion fails. | |
// target: aarch64-linux-gnu | |
extern "C" long double __divtf3(long double a, long double b); | |
int main() { | |
long double result = __divtf3(std::numeric_limits<long double>::min(), 2.0L); | |
uint8_t expected[sizeof(long double)] = { 0x00, | |
0x00, | |
0x00, | |
0x00, | |
0x00, | |
0x00, | |
0x00, | |
0x00, | |
0x00, | |
0x00, | |
0x00, | |
0x00, | |
0x00, | |
0x80, | |
0x00, | |
0x00 }; | |
uint8_t actual[sizeof(long double)]; | |
memcpy(actual, &result, sizeof(long double)); | |
std::cout << "__LDBL_MIN__ / 2.0L = " << result | |
<< ", bit pattern: "; | |
for (size_t i = 0; i < sizeof(actual); ++i) { | |
std::cout << std::hex << std::setfill('0') << std::setw(2) | |
<< (int)actual[i] << ' '; | |
} | |
std::cout << std::endl; | |
assert(memcmp(expected, actual, sizeof(long double)) == 0); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment