(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.dg/
torture/
float128-extendxf-underflow.c
       1  /* Test that extension from XFmode to __float128 raises underflow for
       2     exact tiny values, if trapping on underflow is enabled.  */
       3  
       4  /* { dg-do run { target i?86-*-*gnu* x86_64-*-*gnu* ia64-*-*gnu* } } */
       5  /* { dg-options "-D_GNU_SOURCE" } */
       6  /* { dg-require-effective-target fenv_exceptions } */
       7  
       8  #include <fenv.h>
       9  #include <setjmp.h>
      10  #include <signal.h>
      11  #include <stdlib.h>
      12  
      13  volatile sig_atomic_t caught_sigfpe;
      14  sigjmp_buf buf;
      15  
      16  static void
      17  handle_sigfpe (int sig)
      18  {
      19    caught_sigfpe = 1;
      20    siglongjmp (buf, 1);
      21  }
      22  
      23  int
      24  main (void)
      25  {
      26    volatile long double a = 0x1p-16384L;
      27    volatile __float128 r;
      28    r = a;
      29    if (fetestexcept (FE_UNDERFLOW))
      30      abort ();
      31    if (r != 0x1p-16384q)
      32      abort ();
      33    feenableexcept (FE_UNDERFLOW);
      34    signal (SIGFPE, handle_sigfpe);
      35    if (sigsetjmp (buf, 1) == 0)
      36      r = a;
      37    if (!caught_sigfpe)
      38      abort ();
      39    exit (0);
      40  }