Debian Codegraph @

gcc/testsuite/gfortran.dg/pr100155.f90

raw
1 ! { dg-do run }
2 ! Test the fix for PR100155 in which the parentheses caused an ICE
3 ! in evaluation the specification expression for 'z'. Note that the
4 ! recursive attribute is not a factor in the ICE (see PR105168).
5 ! Contributed by Gerhard Steinmetz <[email protected]>
6 !
7 module m1
8 type t
9 integer, allocatable :: i
10 end type
11 integer :: ctr = 0, vals = 0
12 integer, parameter :: no_calls = 6
13 contains
14 recursive function f(x) result(z)
15 class(t) :: x(:)
16 type(t) :: z(size(x)+1)
17 class(t), allocatable :: a(:)
18 type(t), allocatable :: b(:)
19 ctr = ctr + 1
20 allocate (t :: a(1))
21 a(1)%i = ctr
22 if (ctr <= no_calls - 1) then
23 b = f((a)) ! <== parentheses
24 else
25 allocate (b(a(1)%i))
26 b(1)%i = ctr
27 end if
28 vals = vals + b(1)%i
29 z(1) = t(b(1)%i)
30 end
31 end module m1
32
33 use m1
34 type (t) :: dummy(1)
35 type(t), allocatable :: res(:)
36 dummy = t(1)
37 res = f (dummy);
38 if (ctr /= no_calls) stop 1
39 if (vals /= (2 * sum ([(i, i = 1, no_calls)]) - no_calls)) stop 2
40 if (size (res) /= 2) stop 3
41 deallocate (res)
42 deallocate (dummy(1)%i)
43 end