http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57994
--- Comment #21 from Vincent Lefèvre <vincent-gcc at vinc17 dot net> --- (In reply to Paolo Carlini from comment #19) > If I change fold_builtin_logarithm to pass a true as last argument to > do_mpfr_arg1 (thus 0 is accepted) and do_mpfr_ckconv to accept a folded > result which is infinity, things finally work. Patchlet below. Note however, > that I also need -O1 otherwise, at -O0, we don't try to propagate the > constant num and mpfr isn't used, we again have a library call which returns > -nan. I don't know much about GCC internals, but did you think about exceptions, e.g. FE_DIVBYZERO for log(0)? Note that MPFR's divide-by-zero exception (flag) and associated functions are new in MPFR 3.1.0. > @@ -13527,7 +13527,7 @@ do_mpfr_ckconv (mpfr_srcptr m, tree type, int inex > /* Proceed iff we get a normal number, i.e. not NaN or Inf and no > overflow/underflow occurred. If -frounding-math, proceed iff the > result of calling FUNC was exact. */ > - if (mpfr_number_p (m) && !mpfr_overflow_p () && !mpfr_underflow_p () > + if (!mpfr_nan_p (m) && !mpfr_overflow_p () && !mpfr_underflow_p () > && (!flag_rounding_math || !inexact)) [...] If you do this, don't forget to update the comment. Ditto for the other changes.