Debian Codegraph @

gcc/testsuite/gfortran.dg/PR82376.f90

raw
1 ! { dg-do compile }
2 ! { dg-options "-fdump-tree-original -fcheck=pointer" }
3 !
4 ! Test the fix for PR82376. The pointer check was doubling up the call
5 ! to new. The fix reduces the count of 'new' from 5 to 4, or to 3, when
6 ! counting only calls.
7 !
8 ! Contributed by José Rui Faustino de Sousa <[email protected]>
9 !
10 program main_p
11
12 integer, parameter :: n = 10
13
14 type :: foo_t
15 integer, pointer :: v =>null()
16 end type foo_t
17
18 integer, save :: pcnt = 0
19
20 type(foo_t) :: int
21 integer :: i
22
23 do i = 1, n
24 call init(int, i)
25 if(.not.associated(int%v)) stop 1
26 if(int%v/=i) stop 2
27 if(pcnt/=i) stop 3
28 end do
29
30 contains
31
32 function new(data) result(this)
33 integer, target, intent(in) :: data
34
35 integer, pointer :: this
36
37 nullify(this)
38 this => data
39 pcnt = pcnt + 1
40 return
41 end function new
42
43 subroutine init(this, data)
44 type(foo_t), intent(out) :: this
45 integer, intent(in) :: data
46
47 call set(this, new(data))
48 return
49 end subroutine init
50
51 subroutine set(this, that)
52 type(foo_t), intent(inout) :: this
53 integer, target, intent(in) :: that
54
55 this%v => that
56 return
57 end subroutine set
58
59 end program main_p
60 ! { dg-final { scan-tree-dump-times { new \(} 3 "original" } }