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

--- Comment #6 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Aliasing rules are NOT a local thing and they are not about what the type of
the pointer is, rather than they are about the access after the casting. They
are also global ...

GCC used to have strict aliasing warnings which might warn during optimizations
but it had many false positives so it was tuned down a lot.
The rules are simple in most cases (there are complex parts to it when dealing
with unions and structures but more complex in the implementation of the
compiler).

Some reading on this subject:
https://developers.redhat.com/blog/2020/06/02/the-joys-and-perils-of-c-and-c-aliasing-part-1
https://gist.github.com/shafik/848ae25ee209f698763cffee272a58f8

There are many more papers about C/C++ aliasing rules if you want to go read up
on why GCC is doing the "correct" thing here.

Reply via email to