1! RUN: %B/test/Semantics/test_errors.sh %s %flang %t
2! Tests valid and invalid ENTRY statements
3
4module m1
5  !ERROR: ENTRY may appear only in a subroutine or function
6  entry badentryinmodule
7  interface
8    module subroutine separate
9    end subroutine
10  end interface
11 contains
12  subroutine modproc
13    entry entryinmodproc ! ok
14    block
15      !ERROR: ENTRY may not appear in an executable construct
16      entry badentryinblock ! C1571
17    end block
18    if (.true.) then
19      !ERROR: ENTRY may not appear in an executable construct
20      entry ibadconstr() ! C1571
21    end if
22   contains
23    subroutine internal
24      !ERROR: ENTRY may not appear in an internal subprogram
25      entry badentryininternal ! C1571
26    end subroutine
27  end subroutine
28end module
29
30submodule(m1) m1s1
31 contains
32  module procedure separate
33    !ERROR: ENTRY may not appear in a separate module procedure
34    entry badentryinsmp ! 1571
35  end procedure
36end submodule
37
38program main
39  !ERROR: ENTRY may appear only in a subroutine or function
40  entry badentryinprogram ! C1571
41end program
42
43block data bd1
44  !ERROR: ENTRY may appear only in a subroutine or function
45  entry badentryinbd ! C1571
46end block data
47
48subroutine subr(goodarg1)
49  real, intent(in) :: goodarg1
50  real :: goodarg2
51  !ERROR: A dummy argument may not also be a named constant
52  integer, parameter :: badarg1 = 1
53  type :: badarg2
54  end type
55  common /badarg3/ x
56  namelist /badarg4/ x
57  !ERROR: A dummy argument may not have the SAVE attribute
58  integer :: badarg5 = 2
59  entry okargs(goodarg1, goodarg2)
60  !ERROR: RESULT(br1) may appear only in a function
61  entry badresult() result(br1) ! C1572
62  !ERROR: ENTRY dummy argument 'badarg2' is previously declared as an item that may not be used as a dummy argument
63  !ERROR: ENTRY dummy argument 'badarg4' is previously declared as an item that may not be used as a dummy argument
64  entry badargs(badarg1,badarg2,badarg3,badarg4,badarg5)
65end subroutine
66
67function ifunc()
68  integer :: ifunc
69  integer :: ibad1
70  type :: ibad2
71  end type
72  save :: ibad3
73  real :: weird1
74  double precision :: weird2
75  complex :: weird3
76  logical :: weird4
77  character :: weird5
78  type(ibad2) :: weird6
79  integer :: iarr(1)
80  integer, allocatable :: alloc
81  integer, pointer :: ptr
82  entry iok1()
83  !ERROR: ENTRY name 'ibad1' may not be declared when RESULT() is present
84  entry ibad1() result(ibad1res) ! C1570
85  !ERROR: 'ibad2' was previously declared as an item that may not be used as a function result
86  entry ibad2()
87  !ERROR: ENTRY in a function may not have an alternate return dummy argument
88  entry ibadalt(*) ! C1573
89  !ERROR: RESULT(ifunc) may not have the same name as the function
90  entry isameres() result(ifunc) ! C1574
91  entry iok()
92  !ERROR: RESULT(iok) may not have the same name as an ENTRY in the function
93  entry isameres2() result(iok) ! C1574
94  entry isameres3() result(iok2) ! C1574
95  entry iok2()
96  !These cases are all acceptably incompatible
97  entry iok3() result(weird1)
98  entry iok4() result(weird2)
99  entry iok5() result(weird3)
100  entry iok6() result(weird4)
101  !ERROR: Result of ENTRY is not compatible with result of containing function
102  entry ibadt1() result(weird5)
103  !ERROR: Result of ENTRY is not compatible with result of containing function
104  entry ibadt2() result(weird6)
105  !ERROR: Result of ENTRY is not compatible with result of containing function
106  entry ibadt3() result(iarr)
107  !ERROR: Result of ENTRY is not compatible with result of containing function
108  entry ibadt4() result(alloc)
109  !ERROR: Result of ENTRY is not compatible with result of containing function
110  entry ibadt5() result(ptr)
111  call isubr
112  !ERROR: 'isubr' was previously called as a subroutine
113  entry isubr()
114  continue ! force transition to execution part
115  entry implicit()
116  implicit = 666 ! ok, just ensure that it works
117end function
118
119function chfunc() result(chr)
120  character(len=1) :: chr
121  character(len=2) :: chr1
122  !ERROR: Result of ENTRY is not compatible with result of containing function
123  entry chfunc1() result(chr1)
124end function
125
126subroutine externals
127  !ERROR: 'subr' is already defined as a global identifier
128  entry subr
129  !ERROR: 'ifunc' is already defined as a global identifier
130  entry ifunc
131  !ERROR: 'm1' is already defined as a global identifier
132  entry m1
133  !ERROR: 'iok1' is already defined as a global identifier
134  entry iok1
135  integer :: ix
136  ix = iproc()
137  !ERROR: 'iproc' was previously called as a function
138  entry iproc
139end subroutine
140
141module m2
142  external m2entry2
143 contains
144  subroutine m2subr1
145    entry m2entry1 ! ok
146    entry m2entry2 ! ok
147    entry m2entry3 ! ok
148  end subroutine
149end module
150
151subroutine usem2
152  use m2
153  interface
154    subroutine simplesubr
155    end subroutine
156  end interface
157  procedure(simplesubr), pointer :: p
158  p => m2subr1 ! ok
159  p => m2entry1 ! ok
160  p => m2entry2 ! ok
161  p => m2entry3 ! ok
162end subroutine
163
164module m3
165  interface
166    module subroutine m3entry1
167    end subroutine
168  end interface
169 contains
170  subroutine m3subr1
171    !ERROR: 'm3entry1' is already declared in this scoping unit
172    entry m3entry1
173  end subroutine
174end module
175
176function inone
177  implicit none
178  integer :: inone
179  !ERROR: No explicit type declared for 'implicitbad1'
180  entry implicitbad1
181  inone = 0 ! force transition to execution part
182  !ERROR: No explicit type declared for 'implicitbad2'
183  entry implicitbad2
184end
185