OSDN Git Service

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