real_convert (&result, mode, &value);
/* Don't constant fold this floating point operation if
+ both operands are not NaN but the result is NaN, and
+ flag_trapping_math. Such operations should raise an
+ invalid operation exception. */
+ if (flag_trapping_math
+ && MODE_HAS_NANS (mode)
+ && REAL_VALUE_ISNAN (result)
+ && !REAL_VALUE_ISNAN (d1)
+ && !REAL_VALUE_ISNAN (d2))
+ return NULL_TREE;
+
+ /* Don't constant fold this floating point operation if
the result has overflowed and flag_trapping_math. */
if (flag_trapping_math
&& MODE_HAS_INFINITIES (mode)
--- /dev/null
+/* { dg-do run } */
+/* { dg-options "-O2 -ftrapping-math" } */
+/* { dg-add-options ieee } */
+/* { dg-require-effective-target fenv_exceptions } */
+
+#include <fenv.h>
+#include <stdlib.h>
+
+double
+x (void)
+{
+ double d = __builtin_inf ();
+ return d / d;
+}
+
+int
+main (void)
+{
+ double r = x ();
+ if (!__builtin_isnan (r))
+ abort ();
+ if (!fetestexcept (FE_INVALID))
+ abort ();
+ exit (0);
+}