Debian Codegraph @

gcc/testsuite/gfortran.dg/proc_ptr_52.f90

raw
1 ! { dg-do run }
2 ! { dg-additional-options "-fcheck=pointer" }
3 !
4 ! Test the fix for PRs93924 & 93925.
5 !
6 ! Contributed by Martin Stein <[email protected]>
7 !
8 module cs
9
10 implicit none
11
12 integer, target :: integer_target
13
14 abstract interface
15 function classStar_map_ifc(x) result(y)
16 class(*), pointer :: y
17 class(*), target, intent(in) :: x
18 end function classStar_map_ifc
19 end interface
20
21 contains
22
23 function fun(x) result(y)
24 class(*), pointer :: y
25 class(*), target, intent(in) :: x
26 select type (x)
27 type is (integer)
28 integer_target = x ! Deals with dangling target.
29 y => integer_target
30 class default
31 y => null()
32 end select
33 end function fun
34
35 function apply(f, x) result(y)
36 procedure(classStar_map_ifc) :: f
37 integer, intent(in) :: x
38 integer :: y
39 class(*), pointer :: p
40 y = 0 ! Get rid of 'y' undefined warning
41 p => f (x)
42 select type (p)
43 type is (integer)
44 y = p
45 end select
46 end function apply
47
48 function selector() result(f)
49 procedure(classStar_map_ifc), pointer :: f
50 f => fun
51 end function selector
52
53 end module cs
54
55
56 program classStar_map
57
58 use cs
59 implicit none
60
61 integer :: x, y
62 procedure(classStar_map_ifc), pointer :: f
63
64 x = 123654
65 f => selector () ! Fixed by second chunk in patch
66 y = apply (f, x) ! Fixed by first chunk in patch
67 if (x .ne. y) stop 1
68
69 x = 2 * x
70 y = apply (fun, x) ! PR93925; fixed as above
71 if (x .ne. y) stop 2
72
73 end program classStar_map