https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81694
--- Comment #5 from Alexander Monakov <amonakov at gcc dot gnu.org> --- GCC exploits undefined behavior throughout the compilation pipeline, if you want a methodical workaround, you need compilation mode that makes overflow defined (-fwrapv), and likewise for other sources of undefined behavior. A few links to related discussion are available at https://gcc.gnu.org/wiki/boringcc