Debian Codegraph @

gcc/testsuite/gfortran.dg/pr109345.f90

raw
1 ! { dg-do run }
2 !
3 ! Test the fix for PR109345 in which array references in the SELECT TYPE
4 ! block below failed because the descriptor span was not set correctly.
5 !
6 ! Contributed by Lauren Chilutti <[email protected]>
7 !
8 program test
9 implicit none
10 type :: t
11 character(len=12, kind=4) :: str_array(4)
12 integer :: i
13 end type
14 character(len=12, kind=1), target :: str_array(4)
15 character(len=12, kind=4), target :: str_array4(4)
16 type(t) :: str_t (4)
17 integer :: i
18
19 str_array(:) = ""
20 str_array(1) = "12345678"
21 str_array(2) = "@ABCDEFG"
22 ! Original failing test
23 call foo (str_array)
24
25 str_array4(:) = ""
26 str_array4(1) = "12345678"
27 str_array4(2) = "@ABCDEFG"
28 str_t = [(t(str_array4, i), i = 1, 4)]
29 ! Test character(kind=4)
30 call foo (str_t(2)%str_array)
31 ! Test component references
32 call foo (str_t%str_array(1), .true.)
33 ! Test component references and that array offset is correct.
34 call foo (str_t(2:3)%i)
35
36 contains
37 subroutine foo (var, flag)
38 class(*), intent(in) :: var(:)
39 integer(kind=4) :: i
40 logical, optional :: flag
41 select type (var)
42 type is (character(len=*, kind=1))
43 if (len (var) /= 12) stop 1
44 ! Scalarised array references worked.
45 if (any (var /= str_array)) stop 2
46 do i = 1, size(var)
47 ! Elemental array references did not work.
48 if (trim (var(i)) /= trim (str_array(i))) stop 3
49 enddo
50
51 type is (character(len=*, kind=4))
52 if (len (var) /= 12) stop 4
53 ! Scalarised array references worked.
54 if (any (var /= var(1))) then
55 if (any (var /= str_array4)) stop 5
56 else
57 if (any (var /= str_array4(1))) stop 6
58 end if
59 do i = 1, size(var)
60 ! Elemental array references did not work.
61 if (var(i) /= var(1)) then
62 if (present (flag)) stop 7
63 if (trim (var(i)) /= trim (str_array4(i))) stop 8
64 else
65 if (trim (var(i)) /= trim (str_array4(1))) stop 9
66 end if
67 enddo
68
69 type is (integer(kind=4))
70 if (any(var /= [2,3])) stop 10
71 do i = 1, size (var)
72 if (var(i) /= i+1) stop 11
73 end do
74 end select
75 end
76 end
77