|
Packit |
6c4009 |
/* BZ 12420 */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#include <errno.h>
|
|
Packit |
6c4009 |
#include <fenv.h>
|
|
Packit |
6c4009 |
#include <stdio.h>
|
|
Packit |
6c4009 |
#include <stdlib.h>
|
|
Packit |
6c4009 |
#include <ucontext.h>
|
|
Packit |
6c4009 |
#include <libc-diag.h>
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
static int
|
|
Packit |
6c4009 |
do_test (void)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
if (FE_ALL_EXCEPT == 0)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
printf("Skipping test; no support for FP exceptions.\n");
|
|
Packit |
6c4009 |
return 0;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
int except_mask = 0;
|
|
Packit |
6c4009 |
#ifdef FE_DIVBYZERO
|
|
Packit |
6c4009 |
except_mask |= FE_DIVBYZERO;
|
|
Packit |
6c4009 |
#endif
|
|
Packit |
6c4009 |
#ifdef FE_INVALID
|
|
Packit |
6c4009 |
except_mask |= FE_INVALID;
|
|
Packit |
6c4009 |
#endif
|
|
Packit |
6c4009 |
#ifdef FE_OVERFLOW
|
|
Packit |
6c4009 |
except_mask |= FE_OVERFLOW;
|
|
Packit |
6c4009 |
#endif
|
|
Packit |
6c4009 |
#ifdef FE_UNDERFLOW
|
|
Packit |
6c4009 |
except_mask |= FE_UNDERFLOW;
|
|
Packit |
6c4009 |
#endif
|
|
Packit |
6c4009 |
int status = feenableexcept (except_mask);
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
except_mask = fegetexcept ();
|
|
Packit |
6c4009 |
if (except_mask == -1)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
printf("\nBefore getcontext(): fegetexcept returned: %d\n",
|
|
Packit |
6c4009 |
except_mask);
|
|
Packit |
6c4009 |
return 1;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
ucontext_t ctx;
|
|
Packit |
6c4009 |
status = getcontext(&ctx;;
|
|
Packit |
6c4009 |
if (status)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
printf("\ngetcontext failed, errno: %d.\n", errno);
|
|
Packit |
6c4009 |
return 1;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
printf ("\nDone with getcontext()!\n");
|
|
Packit |
6c4009 |
fflush (NULL);
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* On nios2 GCC 5 warns that except_mask may be used
|
|
Packit |
6c4009 |
uninitialized. Because it is always initialized and nothing in
|
|
Packit |
6c4009 |
this test ever calls setcontext (a setcontext call could result
|
|
Packit |
6c4009 |
in local variables being clobbered on the second return from
|
|
Packit |
6c4009 |
getcontext), in fact an uninitialized use is not possible. */
|
|
Packit |
6c4009 |
DIAG_PUSH_NEEDS_COMMENT;
|
|
Packit |
6c4009 |
DIAG_IGNORE_NEEDS_COMMENT (5, "-Wmaybe-uninitialized");
|
|
Packit |
6c4009 |
int mask = fegetexcept ();
|
|
Packit |
6c4009 |
if (mask != except_mask)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
printf("\nAfter getcontext(): fegetexcept returned: %d, expected: %d.\n",
|
|
Packit |
6c4009 |
mask, except_mask);
|
|
Packit |
6c4009 |
return 1;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
printf("\nAt end fegetexcept() returned %d, expected: %d.\n",
|
|
Packit |
6c4009 |
mask, except_mask);
|
|
Packit |
6c4009 |
DIAG_POP_NEEDS_COMMENT;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
return 0;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#define TEST_FUNCTION do_test ()
|
|
Packit |
6c4009 |
#include "../test-skeleton.c"
|