OSDN Git Service

2004-07-17 Jeroen Frijters <jeroen@frijters.net>
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / g77.dg / gcov / gcov-1.f
1 C { dg-options "-fprofile-arcs -ftest-coverage" }
2 C { dg-do run { target native } }
3 C
4 C Test gcov reports for line counts and branch and call return percentages
5 C for various Fortran 77 constructs to catch basic regressions in the
6 C functionality.
7
8       program gcov1
9       implicit none
10       integer i,j,k,n
11       integer result
12       integer lpall, ieall, gtall
13       integer lpval, ieval, gtval
14
15                                         ! returns(100)
16       lpval = lpall()                   ! count(1)
17                                         ! returns(100)
18       ieval = ieall()                   ! count(1)
19                                         ! returns(100)
20       gtval = gtall()                   ! count(1)
21                                         ! returns(end)
22       if ((lpval .ne. 1) .or. (ieval .ne. 1) .or. (gtval .ne. 1)) then
23          call abort
24       end if
25       
26       end
27
28 C Pass a value through a function to thwart optimization.
29       integer function foo(i)
30       implicit none
31       integer i
32       foo = i                           ! count(18)
33       end
34
35 C Test various flavors of GOTO and compare results against expected values.
36       integer function gtall()
37       implicit none
38       integer gt1, gt2, gt3, gt4, gt5
39       integer gtval
40
41       gtall = 1                         ! count(1)
42       gtval = 0                         ! count(1)
43                                         ! returns(100)
44       gtval = gtval + gt1(0)            ! count(1)
45                                         ! returns(100)
46       gtval = gtval + gt1(1)            ! count(1)
47                                         ! returns(end)
48                                         ! branch(0)
49       if (gtval .ne. 3) then            ! count(1)
50                                         ! branch(end)
51          print *,"gtall part 1:  ", gtval, 3
52          gtall = 0
53       end if
54
55       gtval = 0                         ! count(1)
56                                         ! returns(100)
57       gtval = gtval + gt2(9)            ! count(1)
58                                         ! returns(100)
59       gtval = gtval + gt2(20)           ! count(1)
60                                         ! returns(end)
61                                         ! branch(0)
62       if (gtval .ne. 12) then           ! count(1)
63                                         ! branch(end)
64          print *,"gtall part 2:  ", gtval, 12
65          gtall = 0
66       end if
67
68       gtval = 0                         ! count(1)
69                                         ! returns(100)
70       gtval = gtval + gt3(0)            ! count(1)
71                                         ! returns(100)
72       gtval = gtval + gt3(3)            ! count(1)
73                                         ! returns(end)
74                                         ! branch(0)
75       if (gtval .ne. 48) then           ! count(1)
76                                         ! branch(end)
77                                         ! branch(end)
78          print *,"gtall part 3:  ", gtval, 48
79          gtall = 0
80       end if
81
82       gtval = 0                         ! count(1)
83                                         ! returns(100)
84       gtval = gtval + gt4(1)            ! count(1)
85                                         ! returns(100)
86       gtval = gtval + gt4(2)            ! count(1)
87                                         ! returns(100)
88       gtval = gtval + gt4(3)            ! count(1)
89                                         ! returns(end)
90                                         ! branch(0)
91       if (gtval .ne. 14) then           ! count(1)
92                                         ! branch(end)
93          print *,"gtall part 4:  ", gtval, 14
94          gtall = 0
95       end if
96
97       gtval = 0                         ! count(1)
98                                         ! returns(100)
99       gtval = gtval + gt5(0)            ! count(1)
100                                         ! returns(100)
101       gtval = gtval + gt5(-1)           ! count(1)
102                                         ! returns(100)
103       gtval = gtval + gt5(5)            ! count(1)
104                                         ! returns(end)
105                                         ! branch(0)
106       if (gtval .ne. 14) then           ! count(1)
107                                         ! branch(end)
108          print *,"gtall part 5:  ", gtval, 14
109          gtall = 0
110       end if
111       end
112
113 C Test simple GOTO.
114       integer function gt1(f)
115       implicit none
116       integer f
117                                         ! branch(50)
118       if (f .ne. 0) goto 100            ! count(2)
119                                         ! branch(end)
120       gt1 = 1                           ! count(1)
121       goto 101                          ! count(1)
122   100 gt1 = 2                           ! count(1)
123   101 continue                          ! count(2)
124       end
125
126 C Test simple GOTO again, this time out of a DO loop.
127       integer function gt2(f)
128       implicit none
129       integer f
130       integer i
131                                         ! branch(95)
132       do i=1,10
133                                         ! branch(end)
134          if (i .eq. f) goto 100         ! count(19)
135       end do
136       gt2 = 4                           ! count(1)
137       goto 101                          ! count(1)
138   100 gt2 = 8                           ! count(1)
139   101 continue                          ! count(2)
140       end
141
142 C Test computed GOTO.
143       integer function gt3(i)
144       implicit none
145       integer i
146       goto (101, 102, 103, 104), i      ! count(2)
147       gt3 = 8                           ! count(1)
148       goto 105                          ! count(1)
149   101 gt3 = 1024
150       goto 105
151   102 gt3 = 2048
152       goto 105
153   103 gt3 = 16                          ! count(1)
154       goto 105                          ! count(1)
155   104 gt3 = 4096
156       goto 105
157   105 gt3 = gt3 * 2                     ! count(2)
158       end
159
160 C Test assigned GOTO.
161       integer function gt4(i)
162       implicit none
163       integer i
164       integer label
165       assign 101 to label               ! count(3)
166       if (i .eq. 2) assign 102 to label ! count(3)
167       if (i .eq. 3) assign 103 to label ! count(3)
168       goto label, (101, 102, 103)       ! count(3)
169   101 gt4 = 1                           ! count(1)
170       goto 104                          ! count(1)
171   102 gt4 = 2                           ! count(1)
172       goto 104                          ! count(1)
173   103 gt4 = 4                           ! count(1)
174   104 gt4 = gt4 * 2                     ! count(3)
175       end
176
177 C Test arithmetic IF (bundled with the GOTO variants).
178       integer function gt5(i)
179       implicit none
180       integer i
181       gt5 = 1                           ! count(3)
182                                         ! branch(67 50)
183       if (i) 101, 102, 103              ! count(3)
184                                         ! branch(end)
185   101 gt5 = 2                           ! count(1)
186       goto 104                          ! count(1)
187   102 gt5 = 4                           ! count(1)
188       goto 104                          ! count(1)
189   103 gt5 = 8                           ! count(1)
190   104 continue                          ! count(3)
191       end
192
193 C Run all of the loop tests and check results against expected values.
194       integer function lpall()
195       implicit none
196       integer loop1, loop2
197       integer loopval
198
199       lpall = 1                         ! count(1)
200       loopval = 0                       ! count(1)
201                                         ! returns(100)
202       loopval = loopval + loop1(1,0)    ! count(1)
203                                         ! returns(100)
204       loopval = loopval + loop1(1,2)    ! count(1)
205                                         ! returns(100)
206       loopval = loopval + loop1(1,7)    ! count(1)
207                                         ! returns(end)
208       if (loopval .ne. 12) then         ! count(1)
209          print *,"lpall part 1:  ", loopval, 12
210          lpall = 0
211       end if
212
213       loopval = 0                               ! count(1)
214                                                 ! returns(100)
215       loopval = loopval + loop2(1,0,0,0)        ! count(1)
216                                                 ! returns(100)
217       loopval = loopval + loop2(1,1,0,0)        ! count(1)
218                                                 ! returns(100)
219       loopval = loopval + loop2(1,1,3,0)        ! count(1)
220                                                 ! returns(100)
221       loopval = loopval + loop2(1,1,3,1)        ! count(1)
222                                                 ! returns(100)
223       loopval = loopval + loop2(1,3,1,5)        ! count(1)
224                                                 ! returns(100)
225       loopval = loopval + loop2(1,3,7,3)        ! count(1)
226                                                 ! returns(end)
227       if (loopval .ne. 87) then                 ! count(1)
228          print *,"lpall part 2:  ", loopval, 87
229          lpall = 0
230       end if
231       end
232
233 C Test a simple DO loop.
234       integer function loop1(r,n)
235       implicit none
236       integer r,n,i
237
238       loop1 = r                         ! count(3)
239                                         ! branch(75)
240       do i=1,n
241                                         ! branch(end)
242          loop1 = loop1 + 1              ! count(9)
243       end do
244       end
245
246 C Test nested DO loops.
247       integer function loop2(r, l, m, n)
248       implicit none
249       integer r,l,m,n
250       integer i,j,k
251       loop2 = r                         ! count(6)
252                                         ! branch(60)
253       do i=1,l
254                                         ! branch(77)
255          do j=1,m
256                                         ! branch(73)
257             do k=1,n
258                                         ! branch(end)
259                loop2 = loop2 + 1        ! count(81)
260             end do
261          end do
262       end do
263       end
264
265 C Test various combinations of IF-THEN-ELSE and check results against
266 C expected values.
267       integer function ieall()
268       implicit none
269       integer ie1, ie2, ie3
270       integer ieval
271       ieall = 1                         ! count(1)
272       ieval = 0                         ! count(1)
273       
274       ieval = ieval + ie1(0,2)          ! count(1)
275       ieval = ieval + ie1(0,0)          ! count(1)
276       ieval = ieval + ie1(1,2)          ! count(1)
277       ieval = ieval + ie1(10,2)         ! count(1)
278       ieval = ieval + ie1(11,11)        ! count(1)
279       if (ieval .ne. 31) then           ! count(1)
280          print *,"ieall part 1:  ", ieval, 31
281          ieall = 0
282       end if
283
284       ieval = 0 
285       ieval = ieval + ie2(0)            ! count(1)
286       ieval = ieval + ie2(2)            ! count(1)
287       ieval = ieval + ie2(2)            ! count(1)
288       ieval = ieval + ie2(2)            ! count(1)
289       ieval = ieval + ie2(3)            ! count(1)
290       ieval = ieval + ie2(3)            ! count(1)
291       if (ieval .ne. 23) then           ! count(1)
292          print *,"ieall part 2:  ", ieval, 23
293          ieall = 0
294       end if
295
296       ieval = 0
297       ieval = ieval + ie3(11,19)        ! count(1)
298       ieval = ieval + ie3(25,27)        ! count(1)
299       ieval = ieval + ie3(11,22)        ! count(1)
300       ieval = ieval + ie3(11,10)        ! count(1)
301       ieval = ieval + ie3(21,32)        ! count(1)
302       ieval = ieval + ie3(21,20)        ! count(1)
303       ieval = ieval + ie3(1,2)          ! count(1)
304       ieval = ieval + ie3(32,31)        ! count(1)
305       ieval = ieval + ie3(3,0)          ! count(1)
306       ieval = ieval + ie3(0,47)         ! count(1)
307       ieval = ieval + ie3(65,65)        ! count(1)
308       if (ieval .ne. 246) then          ! count(1)
309          print *,"ieall part 3:  ", ieval, 246
310          ieall = 0
311       end if
312       end
313
314 C Test IF-THEN-ELSE.
315       integer function ie1(i,j)
316       implicit none
317       integer i,j
318       integer foo
319
320       ie1 = 0                           ! count(5)
321                                         ! branch(40)
322       if (i .ne. 0) then                ! count(5)
323                                         ! branch(0)
324          if (j .ne. 0) then             ! count(3)
325                                         ! branch(end)
326             ie1 = foo(4)                ! count(3)
327          else
328             ie1 = foo(1024)
329          end if
330       else
331                                         ! branch(50)
332          if (j .ne. 0) then             ! count(2)
333                                         ! branch(end)
334             ie1 = foo(1)                ! count(1)
335          else
336             ie1 = foo(2)                ! count(1)
337          end if
338       end if
339                                         ! branch(80)
340       if (i .gt. j) then                ! count(5)
341                                         ! branch(end)
342          ie1 = foo(ie1*2)
343       end if
344                                         ! branch(80)
345       if (i .gt. 10) then               ! count(5)
346                                         ! branch(0)
347          if (j .gt. 10) then            ! count(1)
348                                         ! branch(end)
349             ie1 = foo(ie1*4)            ! count(1)
350          end if
351       end if
352       end
353
354 C Test a series of simple IF-THEN statements.
355       integer function ie2(i)
356       implicit none
357       integer i
358       integer foo
359       ie2 = 0                           ! count(6)
360
361                                         ! branch(83)
362       if (i .eq. 0) then                ! count(6)
363                                         ! branch(end)
364          ie2 = foo(1)                   ! count(1)
365       end if
366                                         ! branch(100)
367       if (i .eq. 1) then                ! count(6)
368                                         ! branch(end)
369          ie2 = foo(1024)
370       end if
371                                         ! branch(50)
372       if (i .eq. 2) then                ! count(6)
373                                         ! branch(end)
374          ie2 = foo(2)                   ! count(3)
375       end if
376                                         ! branch(67)
377       if (i .eq. 3) then                ! count(6)
378                                         ! branch(end)
379          ie2 = foo(8)                   ! count(2)
380       end if
381                                         ! branch(100)
382       if (i .eq. 4) then                ! count(6)
383                                         ! branch(end)
384          ie2 = foo(2048)
385       end if
386
387       end
388
389 C Test nested IF statements and IF with compound expressions.
390       integer function ie3(i,j)
391       implicit none
392       integer i,j
393       integer foo
394
395       ie3 = 1                           ! count(11)
396                                         ! branch(27 50 75)
397       if ((i .gt. 10) .and. (j .gt. i) .and. (j .lt. 20)) then ! count(11)
398                                         ! branch(end)
399          ie3 = foo(16)                  ! count(1)
400       end if
401                                         ! branch(55)
402       if (i .gt. 20) then               ! count(11)
403                                         ! branch(60)
404          if (j .gt. i) then             ! count(5)
405                                         ! branch(50)
406             if (j .lt. 30) then         ! count(2)
407                                         ! branch(end)
408                ie3 = foo(32)            ! count(1)
409             end if
410          end if
411       end if
412                                         ! branch(9 10 11)
413       if ((i .eq. 3) .or. (j .eq. 47) .or. (i .eq.j)) then ! count(11)
414                                         ! branch(end)
415          ie3 = foo(64)                  ! count(3)
416       end if
417       end
418 C
419 C { dg-final { run-gcov branches calls { -b gcov-1.f } } }