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

--- Comment #6 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Fabio Cannizzo from comment #3)
> Using -fno-strict-aliasing the issue disappear, however I am not sure if
> that is a real fix, or if it is merely circumstantial.

When creating the bug report there was a notice at the top of the page:

"Before reporting that GCC compiles your code incorrectly, compile it with gcc
-Wall -Wextra and see whether this shows anything wrong with your code.
Similarly, if compiling with -fno-strict-aliasing -fwrapv makes a difference,
your code probably is not correct."

That is the case here.

> As mentioned, there are many other possible workarounds which also make the
> issue disappear. The most curious one being the one below, where p has type
> __m128i*, and simply casting it to XV* before the assignment, things stop
> working.

Yes, code with undefined behaviour is fragile and unpredictable.

> Worth noting, this code works correctly with Visual Studio and with clang.

Yes. code with undefined behaviour sometimes appears to work correctly with
different compilers, or just with different optimizations enabled.

Reply via email to