aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gfortran.dg/PR82376.f90
blob: b99779ce9d8a41c8a527911ca9854b018851c788 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
! { dg-do compile }
! { dg-options "-fdump-tree-original -fcheck=pointer" }
!
! Test the fix for PR82376. The pointer check was doubling up the call
! to new. The fix reduces the count of 'new' from 5 to 4, or to 3, when
! counting only calls.
!
! Contributed by José Rui Faustino de Sousa  <jrfsousa@gmail.com>
!
program main_p

  integer, parameter :: n = 10

  type :: foo_t
    integer, pointer :: v =>null()
  end type foo_t

  integer, save :: pcnt = 0

  type(foo_t) :: int
  integer     :: i

  do i = 1, n
    call init(int, i)
    if(.not.associated(int%v)) stop 1
    if(int%v/=i) stop 2
    if(pcnt/=i) stop 3
  end do

contains

  function new(data) result(this)
    integer, target, intent(in) :: data

    integer, pointer :: this

    nullify(this)
    this => data
    pcnt = pcnt + 1
    return
  end function new

  subroutine init(this, data)
    type(foo_t), intent(out) :: this
    integer,     intent(in)  :: data

    call set(this, new(data))
    return
  end subroutine init

  subroutine set(this, that)
    type(foo_t),     intent(inout) :: this
    integer, target, intent(in)    :: that

    this%v => that
    return
  end subroutine set

end program main_p
! { dg-final { scan-tree-dump-times { new \(} 3 "original" } }