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?

1. Not everybody uses ubsan even when they should use it.

2. The code can use unreachable annotations if it really needs to leave
some paths unhandled, but really can't live with the branch and trap
instructions. (The C++ standard is getting std::unreachable and std::assume
to do that in a portable way, so there is less excuse for not doing it).

Reply via email to