diff options
Diffstat (limited to 'src/regress/lib/libc/setjmp-fpu/setjmp-fpu.c')
-rw-r--r-- | src/regress/lib/libc/setjmp-fpu/setjmp-fpu.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/regress/lib/libc/setjmp-fpu/setjmp-fpu.c b/src/regress/lib/libc/setjmp-fpu/setjmp-fpu.c new file mode 100644 index 0000000000..bbc562d6bd --- /dev/null +++ b/src/regress/lib/libc/setjmp-fpu/setjmp-fpu.c | |||
@@ -0,0 +1,34 @@ | |||
1 | #include <fenv.h> | ||
2 | #include <setjmp.h> | ||
3 | |||
4 | int | ||
5 | main(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); | ||
16 | |||
17 | /* Mess with the FPU control word. */ | ||
18 | if (rv == 0) { | ||
19 | fesetround(FE_DOWNWARD); | ||
20 | fedisableexcept(FE_DIVBYZERO); | ||
21 | longjmp(env, 1); | ||
22 | /* Verify that the FPU control word is preserved. */ | ||
23 | } else if (rv == 1) { | ||
24 | if (fegetround() != FE_UPWARD | ||
25 | || fegetexcept() != FE_DIVBYZERO) | ||
26 | return (1); | ||
27 | return (0); | ||
28 | /* This is not supposed to happen. */ | ||
29 | } else { | ||
30 | return (1); | ||
31 | } | ||
32 | |||
33 | return (1); | ||
34 | } | ||