On Mon, 31 Jan 2022 at 10:25, Andreas Schwab wrote: > > On Jan 30 2022, Jonathan Wakely via Gcc wrote: > > > On Sun, 30 Jan 2022, 10:58 Jakub Jelinek, <ja...@redhat.com> wrote: > > > >> On Sun, Jan 30, 2022 at 10:50:56AM +0000, Jonathan Wakely wrote: > >> > We could put a trap instruction at the end of the function though, which > >> > would make the result a bit less arbitrary. > >> > > >> > I've come around to thinking that's preferable for cases like this. > >> > >> Depends on which exact cases. > >> Because for > >> int foo (int s) { if (s == 123) return 1; } > >> we want to optimize it into > >> return 1; > >> rather than if (s == 123) return 1; else __builtin_trap (); > >> For debugging we have -fsanitize=undefined > > > > > > What if we inserted the trap for -O0? > > Note that in C it is not an error to fall through the end of a non-void > function if the caller does not use the return value.
Indeed. Theo's program is undefined in C++ and valid in C. I would love to see the trap inserted for C++ though.