https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86945
--- Comment #7 from Richard Biener <rguenth at gcc dot gnu.org> --- With -fsanitize=undefined we get even at -O0 id= 1 <unknown>: runtime error: signed integer overflow: 1 - -2147483647 cannot be represented in type 'integer(kind=4)' ierr1, OK = 0 T <unknown>: runtime error: signed integer overflow: 1 - -2147483648 cannot be represented in type 'integer(kind=4)' ierr2, OK = 0 T so both foo1 and foo2 do not "work".