https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118141
Richard Yao <richard.yao at alumni dot stonybrook.edu> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|RESOLVED |UNCONFIRMED
Resolution|INVALID |---
--- Comment #3 from Richard Yao <richard.yao at alumni dot stonybrook.edu> ---
(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.