summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gfortran.dg/bind_c_usage_14.f03
blob: 2d6726af8ba05440cd7efce9374e2b200f81900a (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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
! { dg-do compile }
! { dg-options "-fdump-tree-original" }
!
! PR fortran/34079
! Bind(C) procedures shall have no character length
! dummy and actual arguments.
!

! SUBROUTINES

subroutine sub1noiso(a, b)
  use iso_c_binding
  implicit none
  character(len=1,kind=c_char) :: a(*), b
  character(len=1,kind=c_char):: x,z
  integer(c_int) :: y
  value :: b
  print *, a(1:2), b
end subroutine sub1noiso

subroutine sub2(a, b) bind(c)
  use iso_c_binding
  implicit none
  character(len=1,kind=c_char) :: a(*), b
  character(len=1,kind=c_char):: x,z
  integer(c_int) :: y
  value :: b
  print *, a(1:2), b
end subroutine sub2

! SUBROUTINES with ENTRY

subroutine sub3noiso(a, b)
  use iso_c_binding
  implicit none
  character(len=1,kind=c_char) :: a(*), b
  character(len=1,kind=c_char):: x,z
  integer(c_int) :: y
  value :: b
  print *, a(1:2), b
entry sub3noisoEntry(x,y,z)
  x = 'd'
end subroutine sub3noiso

subroutine sub4iso(a, b) bind(c)
  use iso_c_binding
  implicit none
  character(len=1,kind=c_char) :: a(*), b
  character(len=1,kind=c_char):: x,z
  integer(c_int) :: y
  value :: b
  print *, a(1:2), b
entry sub4isoEntry(x,y,z)
  x = 'd'
end subroutine sub4iso

subroutine sub5iso(a, b) bind(c)
  use iso_c_binding
  implicit none
  character(len=1,kind=c_char) :: a(*), b
  character(len=1,kind=c_char):: x,z
  integer(c_int) :: y
  value :: b
  print *, a(1:2), b
entry sub5noIsoEntry(x,y,z)
  x = 'd'
end subroutine sub5iso

subroutine sub6NoIso(a, b)
  use iso_c_binding
  implicit none
  character(len=1,kind=c_char) :: a(*), b
  character(len=1,kind=c_char):: x,z
  integer(c_int) :: y
  value :: b
  print *, a(1:2), b
entry sub6isoEntry(x,y,z)
  x = 'd'
end subroutine sub6NoIso

! The subroutines (including entry) should have
! only a char-length parameter if they are not bind(C).
!
! { dg-final { scan-tree-dump "sub1noiso \\(\[^.\]*a, \[^.\]*b, \[^.\]*_a, \[^.\]*_b\\)" "original" } }
! { dg-final { scan-tree-dump "sub2 \\(\[^.\]*a, \[^.\]*b\\)" "original" } }
! { dg-final { scan-tree-dump "sub3noiso \\(\[^.\]*a, \[^.\]*b, \[^.\]*_a, \[^.\]*_b\\)" "original" } }
! { dg-final { scan-tree-dump "sub3noisoentry \\(\[^.\]*x, \[^.\]*y, \[^.\]*z, \[^.\]*_x, \[^.\]*_z\\)" "original" } }
! { dg-final { scan-tree-dump "sub4iso \\(\[^.\]*a, \[^.\]*b\\)" "original" } }
! { dg-final { scan-tree-dump "sub4isoentry \\(\[^.\]*x, \[^.\]*y, \[^.\]*z, \[^.\]*_x, \[^.\]*_z\\)" "original" } }
! { dg-final { scan-tree-dump "sub5iso \\(\[^.\]*a, \[^.\]*b\\)" "original" } }
! { dg-final { scan-tree-dump "sub5noisoentry \\(\[^.\]*x, \[^.\]*y, \[^.\]*z, \[^.\]*_x, \[^.\]*_z\\)" "original" } }
! { dg-final { scan-tree-dump "sub6noiso \\(\[^.\]*a, \[^.\]*b, \[^.\]*_a, \[^.\]*_b\\)" "original" } }
! { dg-final { scan-tree-dump "sub6isoentry \\(\[^.\]*x, \[^.\]*y, \[^.\]*z, \[^.\]*_x, \[^.\]*_z\\)" "original" } }

! The master functions should have always a length parameter
! to ensure sharing a parameter between bind(C) and non-bind(C) works
!
! { dg-final { scan-tree-dump "master.0.sub3noiso \\(\[^.\]*__entry, \[^.\]*z, \[^.\]*y, \[^.\]*x, \[^.\]*b, \[^.\]*a, \[^.\]*_z, \[^.\]*_x, \[^.\]*_b, \[^.\]*_a\\)" "original" } }
! { dg-final { scan-tree-dump "master.1.sub4iso \\(\[^.\]*__entry, \[^.\]*z, \[^.\]*y, \[^.\]*x, \[^.\]*b, \[^.\]*a, \[^.\]*_z, \[^.\]*_x, \[^.\]*_b, \[^.\]*_a\\)" "original" } }
! { dg-final { scan-tree-dump "master.2.sub5iso \\(\[^.\]*__entry, \[^.\]*z, \[^.\]*y, \[^.\]*x, \[^.\]*b, \[^.\]*a, \[^.\]*_z, \[^.\]*_x, \[^.\]*_b, \[^.\]*_a\\)" "original" } }
! { dg-final { scan-tree-dump "master.3.sub6noiso \\(\[^.\]*__entry, \[^.\]*z, \[^.\]*y, \[^.\]*x, \[^.\]*b, \[^.\]*a, \[^.\]*_z, \[^.\]*_x, \[^.\]*_b, \[^.\]*_a\\)" "original" } }

! Thus, the master functions need to be called with length arguments
! present
!
! { dg-final { scan-tree-dump "master.0.sub3noiso .0, 0B, 0B, 0B, b, a, 0, 0, 1, 1\\);" "original" } }
! { dg-final { scan-tree-dump "master.0.sub3noiso .1, z, y, x, 0B, 0B, 1, 1, 0, 0\\);" "original" } }
! { dg-final { scan-tree-dump "master.1.sub4iso .0, 0B, 0B, 0B, b, a, 0, 0, 1, 1\\);" "original" } }
! { dg-final { scan-tree-dump "master.1.sub4iso .1, z, y, x, 0B, 0B, 1, 1, 0, 0\\);" "original" } }
! { dg-final { scan-tree-dump "master.2.sub5iso .0, 0B, 0B, 0B, b, a, 0, 0, 1, 1\\);" "original" } }
! { dg-final { scan-tree-dump "master.2.sub5iso .1, z, y, x, 0B, 0B, 1, 1, 0, 0\\);" "original" } }
! { dg-final { scan-tree-dump "master.3.sub6noiso .0, 0B, 0B, 0B, b, a, 0, 0, 1, 1\\);" "original" } }
! { dg-final { scan-tree-dump "master.3.sub6noiso .1, z, y, x, 0B, 0B, 1, 1, 0, 0\\);" "original" } }

! { dg-final { cleanup-tree-dump "original" } }