]>
Commit | Line | Data |
---|---|---|
75ea32ab UD |
1 | /* BZ 12420 */ |
2 | ||
3 | #include <errno.h> | |
4 | #include <fenv.h> | |
5 | #include <stdio.h> | |
6 | #include <stdlib.h> | |
7 | #include <ucontext.h> | |
e15f7de6 | 8 | #include <libc-diag.h> |
75ea32ab UD |
9 | |
10 | static int | |
11 | do_test (void) | |
12 | { | |
d0cd7d02 AS |
13 | if (FE_ALL_EXCEPT == 0) |
14 | { | |
15 | printf("Skipping test; no support for FP exceptions.\n"); | |
16 | return 0; | |
17 | } | |
18 | ||
19 | int except_mask = 0; | |
20 | #ifdef FE_DIVBYZERO | |
21 | except_mask |= FE_DIVBYZERO; | |
22 | #endif | |
23 | #ifdef FE_INVALID | |
24 | except_mask |= FE_INVALID; | |
25 | #endif | |
26 | #ifdef FE_OVERFLOW | |
27 | except_mask |= FE_OVERFLOW; | |
28 | #endif | |
29 | #ifdef FE_UNDERFLOW | |
30 | except_mask |= FE_UNDERFLOW; | |
31 | #endif | |
75ea32ab UD |
32 | int status = feenableexcept (except_mask); |
33 | ||
34 | except_mask = fegetexcept (); | |
35 | if (except_mask == -1) | |
36 | { | |
37 | printf("\nBefore getcontext(): fegetexcept returned: %d\n", | |
38 | except_mask); | |
39 | return 1; | |
40 | } | |
41 | ||
42 | ucontext_t ctx; | |
43 | status = getcontext(&ctx); | |
44 | if (status) | |
45 | { | |
46 | printf("\ngetcontext failed, errno: %d.\n", errno); | |
47 | return 1; | |
48 | } | |
49 | ||
50 | printf ("\nDone with getcontext()!\n"); | |
51 | fflush (NULL); | |
52 | ||
24d1d8ec | 53 | /* On nios2 GCC 5 warns that except_mask may be used |
84c426b8 JM |
54 | uninitialized. Because it is always initialized and nothing in |
55 | this test ever calls setcontext (a setcontext call could result | |
56 | in local variables being clobbered on the second return from | |
57 | getcontext), in fact an uninitialized use is not possible. */ | |
58 | DIAG_PUSH_NEEDS_COMMENT; | |
59 | DIAG_IGNORE_NEEDS_COMMENT (5, "-Wmaybe-uninitialized"); | |
75ea32ab UD |
60 | int mask = fegetexcept (); |
61 | if (mask != except_mask) | |
62 | { | |
63 | printf("\nAfter getcontext(): fegetexcept returned: %d, expected: %d.\n", | |
64 | mask, except_mask); | |
65 | return 1; | |
66 | } | |
67 | ||
68 | printf("\nAt end fegetexcept() returned %d, expected: %d.\n", | |
69 | mask, except_mask); | |
84c426b8 | 70 | DIAG_POP_NEEDS_COMMENT; |
d0cd7d02 | 71 | |
75ea32ab UD |
72 | return 0; |
73 | } | |
74 | ||
75 | #define TEST_FUNCTION do_test () | |
76 | #include "../test-skeleton.c" |