https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118141
Sam James <sjames at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |sjames at gcc dot gnu.org --- Comment #6 from Sam James <sjames at gcc dot gnu.org> --- (In reply to Richard Yao from comment #3) > (In reply to Andrew Pinski from comment #2) > > for (int i = 0; i < 8; i++) { > > input_vec[i] = ((unsigned int*) input)[i]; > > } > > > > float input[8] = { > > 1.0f, 2.0f, 3.0f, 4.0f, > > 5.0f, 6.0f, 7.8f, 8.0f > > }; > > > > unsigned short output[8]; > > > > // Convert fp32 to bfloat16 > > convert_fp32_to_bfloat16(input, output); > > > > > > You are violating C/C++ aliasing rules. Either use memcpy (with c++20, you > > can use std::bit_cast), an union to do type punning or use > > -fno-strict-aliasing. > > > > Adding -fno-strict-aliasing fixes the issue. > > Where is the strict aliasing rule violation? input is a void pointer. We are > allowed to cast it to another pointer type and use it as per the C > specification. No, you cannot then access it via void*, you have to cast it to the original type and use it (or a compatible type).