bug-getcontext.c 1.7 KB

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