PR 78534, 83704 Handle large formatted I/O
[gcc.git] / libgfortran / config / fpu-glibc.h
index 149e8a3ac92681ea24116afadfef6b6dfdbbd2f2..b928416ee2c2b754c48466bedb3299a7ea08e561 100644 (file)
@@ -1,5 +1,5 @@
 /* FPU-related code for systems with GNU libc.
-   Copyright (C) 2005-2014 Free Software Foundation, Inc.
+   Copyright (C) 2005-2018 Free Software Foundation, Inc.
    Contributed by Francois-Xavier Coudert <coudert@clipper.ens.fr>
 
 This file is part of the GNU Fortran runtime library (libgfortran).
@@ -121,7 +121,41 @@ get_fpu_trap_exceptions (void)
 int
 support_fpu_trap (int flag)
 {
-  return support_fpu_flag (flag);
+  int exceptions = 0;
+  int old;
+
+  if (!support_fpu_flag (flag))
+    return 0;
+
+#ifdef FE_INVALID
+  if (flag & GFC_FPE_INVALID) exceptions |= FE_INVALID;
+#endif
+
+#ifdef FE_DIVBYZERO
+  if (flag & GFC_FPE_ZERO) exceptions |= FE_DIVBYZERO;
+#endif
+
+#ifdef FE_OVERFLOW
+  if (flag & GFC_FPE_OVERFLOW) exceptions |= FE_OVERFLOW;
+#endif
+
+#ifdef FE_UNDERFLOW
+  if (flag & GFC_FPE_UNDERFLOW) exceptions |= FE_UNDERFLOW;
+#endif
+
+#ifdef FE_DENORMAL
+  if (flag & GFC_FPE_DENORMAL) exceptions |= FE_DENORMAL;
+#endif
+
+#ifdef FE_INEXACT
+  if (flag & GFC_FPE_INEXACT) exceptions |= FE_INEXACT;
+#endif
+
+  old = feenableexcept (exceptions);
+  if (old == -1)
+    return 0;
+  fedisableexcept (exceptions & ~old);
+  return 1;
 }
 
 
@@ -333,8 +367,9 @@ get_fpu_rounding_mode (void)
       case FE_TOWARDZERO:
        return GFC_FPE_TOWARDZERO;
 #endif
+
       default:
-       return GFC_FPE_INVALID;
+       return 0; /* Should be unreachable.  */
     }
 }
 
@@ -369,8 +404,9 @@ set_fpu_rounding_mode (int mode)
        rnd_mode = FE_TOWARDZERO;
        break;
 #endif
+
       default:
-       return;
+       return; /* Should be unreachable.  */
     }
 
   fesetround (rnd_mode);
@@ -411,7 +447,7 @@ support_fpu_rounding_mode (int mode)
 #endif
 
       default:
-       return 0;
+       return 0; /* Should be unreachable.  */
     }
 }