summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gfortran.dg/PR93308.f90
blob: ee116f961dee62cf7a632e6b14ac3cfbd64e367d (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
! { dg-do run }
!
! Test the fix for PR94331
!
! Contributed by Robin Hogan <r.j.hogan@reading.ac.uk>
!

program test 

  use, intrinsic :: iso_c_binding, only: &
    c_int, c_float

  implicit none

  integer                       :: i
  integer,            parameter :: n = 11
  real(kind=c_float), parameter :: u(*) = [(real(i, kind=c_float), i=1,n)]
  
  real(kind=c_float), allocatable :: A(:)
  real(kind=c_float)              :: E(n)
  integer(kind=c_int)             :: l1, l2, l3

  allocate(A, source=u)
  l1 = lbound(A, 1)
  call routine_bindc(A, l2) ! in gcc-9.2.1 this changes lbound of A...
  l3 = lbound(A, 1)
  if (l1 /= 1)                        stop 1
  if (l1 /= l2)                       stop 2
  if (l1 /= l3)                       stop 3
  if (any(abs(A(1:n)-u)>0.0_c_float)) stop 4
  deallocate(A)
  !
  E = u
  l1 = lbound(E, 1)
  call routine_bindc(E, l2) ! ...but does not change lbound of E
  l3 = lbound(E, 1)
  if (l1 /= 1)                        stop 5
  if (l1 /= l2)                       stop 6
  if (l1 /= l3)                       stop 7
  if (any(abs(E(1:n)-u)>0.0_c_float)) stop 8

contains

  subroutine routine_bindc(v, l) bind(c)
    real(kind=c_float),  intent(inout) :: v(:)
    integer(kind=c_int), intent(out)   :: l
    
    l = lbound(v, 1)
    if (any(abs(v(1:n)-u)>0.0_c_float)) stop 9
  end subroutine routine_bindc
  
end program test