Debian Codegraph @

gcc/testsuite/gfortran.dg/associate_66.f90

raw
1 ! { dg-do run }
2 ! { dg-options "-fdump-tree-original" }
3 !
4 ! Tests unlimited polymorphic function selectors in ASSOCIATE.
5 !
6 ! Contributed by Harald Anlauf <[email protected]> in
7 ! https://gcc.gnu.org/pipermail/fortran/2024-January/060098.html
8 !
9 program p
10 implicit none
11 ! scalar array
12 associate (var1 => foo1(), var2 => foo2())
13 call prt (var1); call prt (var2)
14 end associate
15 contains
16 ! Scalar value
17 function foo1() result(res)
18 class(*), allocatable :: res
19 res = 42.0
20 end function foo1
21 ! Array value
22 function foo2() result(res)
23 class(*), allocatable :: res(:)
24 res = [42, 84]
25 end function foo2
26 ! Test the associate-name value
27 subroutine prt (x)
28 class(*), intent(in) :: x(..)
29 logical :: ok = .false.
30 select rank(x)
31 rank (0)
32 select type (x)
33 type is (real)
34 if (int(x*10) .eq. 420) ok = .true.
35 end select
36 rank (1)
37 select type (x)
38 type is (integer)
39 if (all (x .eq. [42, 84])) ok = .true.
40 end select
41 end select
42 if (.not.ok) stop 1
43 end subroutine prt
44 end
45 ! { dg-final { scan-tree-dump-times "__builtin_free" 2 "original" } }