https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114700
--- Comment #9 from Richard Biener <rguenth at gcc dot gnu.org> --- That that GCC doesn't promise that -ftrapv preserves all overflows and traps, it merely guarantees that all overflows that actually happen trap. So GCC is fine to contract some expressions where the overall number of overflows can only decrease. That's not a bug with -ftrapv. It is considered a bug with -fsanitize=undefined though.