[Bug tree-optimization/104356] [12 Regression] divide by zero trap is being removed now when it should not be in some cases

ebotcazou at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Thu Feb 3 12:03:40 GMT 2022


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104356

--- Comment #21 from Eric Botcazou <ebotcazou at gcc dot gnu.org> ---
> But sure, so you say that -fnon-call-exceptions makes operations that
> may trap according to the EH machinery well-defined, irrespective of what
> the language standards say?  That certainly makes sense, it doesn't
> make sense to create EH when the situation invokes undefined behavior.
> (but as said above we have to avoid traps in non-EH context as well)

Of course, that's the very and only purpose of -fnon-call-exceptions, see
tree_could_throw_p:

/* Return true if expression T could throw an exception.  */

bool
tree_could_throw_p (tree t)
{
[...]
  if (cfun->can_throw_non_call_exceptions)
    return tree_could_trap_p (t);
  return false;
}

With -fnon-call-exceptions, trapping operations are not UB but throw instead.
What the language (Java, Go, Ada) makes of this exception may vary, but I don't
think that they call it undefined behavior like in the C family of languages.


More information about the Gcc-bugs mailing list