https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118141

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |INVALID

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
    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.

Reply via email to