summaryrefslogtreecommitdiff
path: root/src/regress/lib/libc/setjmp-fpu/setjmp-fpu.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/regress/lib/libc/setjmp-fpu/setjmp-fpu.c')
-rw-r--r--src/regress/lib/libc/setjmp-fpu/setjmp-fpu.c46
1 files changed, 46 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..45b3c1ee0e
--- /dev/null
+++ b/src/regress/lib/libc/setjmp-fpu/setjmp-fpu.c
@@ -0,0 +1,46 @@
1#include <fenv.h>
2#include <setjmp.h>
3
4int
5TEST_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}