gcov-7.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /* Check that gcov correctly reports line counts, branch percentages,
  2. * and call return percentages for functions that call longjmp. */
  3. /* { dg-options "-fprofile-arcs -ftest-coverage" } */
  4. /* { dg-do run { target native } } */
  5. #include <setjmp.h>
  6. extern void abort (void);
  7. extern void exit (int);
  8. jmp_buf env;
  9. int val;
  10. int longjmp_taken;
  11. int bar_enter, bar_exit;
  12. int foo_enter, foo_exit;
  13. void bar (int i)
  14. {
  15. bar_enter++; /* count(3) */
  16. /* branch(67) */
  17. if (i == 0) {
  18. /* branch(end) */
  19. longjmp_taken++; /* count(1) */
  20. longjmp (env, 1);
  21. }
  22. val += i+1;
  23. bar_exit++; /* count(2) */
  24. }
  25. void foo (int i)
  26. {
  27. foo_enter++; /* count(3) */
  28. /* branch(67) */
  29. if (i == 1) {
  30. /* branch(end) */
  31. longjmp_taken++; /* count(1) */
  32. longjmp (env, 2);
  33. }
  34. /* returns(50) */
  35. bar (i); /* count(2) */
  36. /* returns(100) */
  37. bar (7); /* count(1) */
  38. /* returns(end) */
  39. val += 16;
  40. foo_exit++; /* count(1) */
  41. }
  42. int
  43. passed ()
  44. {
  45. return (val == 31 &&
  46. longjmp_taken == 2 &&
  47. foo_enter == 3 &&
  48. foo_exit == 1 &&
  49. bar_enter == 3 &&
  50. bar_exit == 2);
  51. }
  52. void
  53. leave (int i)
  54. {
  55. if (i == 0) {
  56. abort ();
  57. }
  58. exit (0);
  59. }
  60. int
  61. main()
  62. {
  63. int retval;
  64. /* branch(33) */
  65. if ((retval = setjmp (env))) {
  66. /* branch(end) */
  67. val += retval; /* count(2) */
  68. }
  69. /* returns(33) */
  70. foo (val); /* count(3) */
  71. /* returns(0) */
  72. leave (passed()); /* count(1) */
  73. /* returns(end) */
  74. }
  75. /* { dg-final { run-gcov calls branches { -b gcov-7.c } } } */