https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98168
--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> --- (In reply to Ilya Kurdyukov from comment #0) > Thus, optimizations that falsely assume that the target machine is > performing signed integer saturation when it is not - should be considered > dangerous. That's not what the optimizations assume though. They assume that you write correct code without undefined behaviour. If you want to be able to write invalid C and get predictable results, use the compiler options that allow you to do that. There are several, as mentioned above (and which you should have tried before filing PR 98159, as requested by https://gcc.gnu.org/bugs which you were asked to read by the banner at the top of the new bug form). > In my opinion, UB in C has a different purpose, it exists because C is a > low-level language and in most cases can use a single machine instruction > for a general operation. So for compilers it should be "target machine > behavior", not "we can do anything". And compilers must maintain this > behavior while removing some operations when optimizing the code. You are welcome to your opinion. https://blog.regehr.org/archives/213 (and parts 2 and 3 of the series) is a good read.