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.c21
1 files changed, 11 insertions, 10 deletions
diff --git a/src/regress/lib/libc/setjmp-fpu/setjmp-fpu.c b/src/regress/lib/libc/setjmp-fpu/setjmp-fpu.c
index 11d616ae71..3cdf906e97 100644
--- a/src/regress/lib/libc/setjmp-fpu/setjmp-fpu.c
+++ b/src/regress/lib/libc/setjmp-fpu/setjmp-fpu.c
@@ -1,3 +1,5 @@
1/* $OpenBSD: setjmp-fpu.c,v 1.5 2020/01/16 13:04:02 bluhm Exp $ */
2
1#include <err.h> 3#include <err.h>
2#include <fenv.h> 4#include <fenv.h>
3#include <setjmp.h> 5#include <setjmp.h>
@@ -6,12 +8,13 @@ int
6TEST_SETJMP(void) 8TEST_SETJMP(void)
7{ 9{
8 JMP_BUF env; 10 JMP_BUF env;
11 fexcept_t flag;
9 int rv; 12 int rv;
10 13
11 /* Set up the FPU control word register. */ 14 /* Set up the FPU control word register. */
12 rv = fesetround(FE_UPWARD); 15 rv = fesetround(FE_UPWARD);
13 if (rv != 0) 16 if (rv != 0)
14 errx(1, "fesetround FE_UPWARD returned %d", rv); 17 errx(2, "fesetround FE_UPWARD returned %d", rv);
15 fedisableexcept(FE_ALL_EXCEPT); 18 fedisableexcept(FE_ALL_EXCEPT);
16 feenableexcept(FE_DIVBYZERO); 19 feenableexcept(FE_DIVBYZERO);
17 20
@@ -19,25 +22,22 @@ TEST_SETJMP(void)
19 22
20 switch(rv) { 23 switch(rv) {
21 case 0: { 24 case 0: {
22 fexcept_t flag = FE_OVERFLOW;
23
24 /* Mess with the FPU control word. */ 25 /* Mess with the FPU control word. */
25 rv = fesetround(FE_DOWNWARD); 26 rv = fesetround(FE_DOWNWARD);
26 if (rv != 0) 27 if (rv != 0)
27 errx(1, "fesetround FE_DOWNWARD returned %d", rv); 28 errx(2, "fesetround FE_DOWNWARD returned %d", rv);
28 fedisableexcept(FE_DIVBYZERO); 29 fedisableexcept(FE_DIVBYZERO);
29 30
30 /* Set the FPU exception flags. */ 31 /* Set the FPU exception flags. */
32 flag = FE_OVERFLOW;
31 rv = fesetexceptflag(&flag, FE_ALL_EXCEPT); 33 rv = fesetexceptflag(&flag, FE_ALL_EXCEPT);
32 if (rv != 0) 34 if (rv != 0)
33 errx(1, "fesetexceptflag returned %d", rv); 35 errx(2, "fesetexceptflag returned %d", rv);
34 36
35 LONGJMP(env, 1); 37 LONGJMP(env, 1);
36 errx(1, "longjmp returned"); 38 errx(2, "longjmp returned");
37 } 39 }
38 case 1: { 40 case 1: {
39 fexcept_t flag = 0;
40
41 /* Verify that the FPU control word is preserved. */ 41 /* Verify that the FPU control word is preserved. */
42 rv = fegetround(); 42 rv = fegetround();
43 if (rv != FE_UPWARD) 43 if (rv != FE_UPWARD)
@@ -48,15 +48,16 @@ TEST_SETJMP(void)
48 rv); 48 rv);
49 49
50 /* Verify that the FPU exception flags weren't clobbered. */ 50 /* Verify that the FPU exception flags weren't clobbered. */
51 flag = 0;
51 rv = fegetexceptflag(&flag, FE_ALL_EXCEPT); 52 rv = fegetexceptflag(&flag, FE_ALL_EXCEPT);
52 if (rv != 0) 53 if (rv != 0)
53 errx(1, "fegetexceptflag returned %d", rv); 54 errx(2, "fegetexceptflag returned %d", rv);
54 if (flag != FE_OVERFLOW) 55 if (flag != FE_OVERFLOW)
55 errx(1, "except flag is %d, no FE_OVERFLOW", rv); 56 errx(1, "except flag is %d, no FE_OVERFLOW", rv);
56 57
57 return (0); 58 return (0);
58 } 59 }
59 default: 60 default:
60 errx(1, "setjmp returned %d", rv); 61 errx(2, "setjmp returned %d", rv);
61 } 62 }
62} 63}