1 #include <fenv.h> 2 #include <setjmp.h> 3 4 int 5 TEST_SETJMP(int argc, char *argv[]) 6 { 7 JMP_BUF env; 8 int rv; 9 10 /* Set up the FPU control word register. */ 11 fesetround(FE_UPWARD); 12 fedisableexcept(FE_ALL_EXCEPT); 13 feenableexcept(FE_DIVBYZERO); 14 15 rv = SETJMP(env, 0); 16 17 if (rv == 0) { 18 fexcept_t flag = FE_OVERFLOW; 19 20 /* Mess with the FPU control word. */ 21 fesetround(FE_DOWNWARD); 22 fedisableexcept(FE_DIVBYZERO); 23 24 /* Set the FPU exception flags. */ 25 fesetexceptflag(&flag, FE_ALL_EXCEPT); 26 27 LONGJMP(env, 1); 28 } else if (rv == 1) { 29 fexcept_t flag = 0; 30 31 /* Verify that the FPU control word is preserved. */ 32 if (fegetround() != FE_UPWARD 33 || fegetexcept() != FE_DIVBYZERO) 34 return (1); 35 36 /* Verify that the FPU exception flags weren't clobbered. */ 37 fegetexceptflag(&flag, FE_ALL_EXCEPT); 38 if (flag != FE_OVERFLOW) 39 return (1); 40 41 return (0); 42 } 43 44 /* This is not supposed to happen. */ 45 return (1); 46 } 47