Open llvmbot opened 4 years ago
This code also fails with gcc compiled with -O3. It passes on both clang and gcc if you add -fno-strict-aliasing to the command line. I believe the problem lies in the reinterpret cast used to turn the float into a uint32_t.
This is a way to turn the float into a uint32_t and back that avoids the issue
inline
void swap(float & value)
{
uint32_t tmp;
memcpy(&tmp, &value, sizeof(float));
swap(tmp);
memcpy(&value, &tmp, sizeof(float));
}
Extended Description
The following code runs OK in Compiler Explorer with opts: -std=c++11 -O1 Fails running: -std=c++11 -O3 Byte swapping is omitted.