xref: /llvm-project/flang/test/Semantics/local-vs-global.f90 (revision 8ed8210690816084159a166bf698c16ce9ed6a9b)
1! RUN: %python %S/test_errors.py %s %flang_fc1 -pedantic
2
3module module_before_1
4end
5
6module module_before_2
7end
8
9block data block_data_before_1
10end
11
12block data block_data_before_2
13end
14
15subroutine explicit_before_1(a)
16  real, optional :: a
17end
18
19subroutine explicit_before_2(a)
20  real, optional :: a
21end
22
23subroutine implicit_before_1(a)
24  real :: a
25end
26
27subroutine implicit_before_2(a)
28  real :: a
29end
30
31function explicit_func_before_1(a)
32  real, optional :: a
33end
34
35function explicit_func_before_2(a)
36  real, optional :: a
37end
38
39function implicit_func_before_1(a)
40  real :: a
41end
42
43function implicit_func_before_2(a)
44  real :: a
45end
46
47program test
48  external justfine ! OK to name a BLOCK DATA if not called
49  !WARNING: The global entity 'module_before_1' corresponding to the local procedure 'module_before_1' is not a callable subprogram
50  external module_before_1
51  !WARNING: The global entity 'block_data_before_1' corresponding to the local procedure 'block_data_before_1' is not a callable subprogram
52  external block_data_before_1
53  !WARNING: The global subprogram 'explicit_before_1' should not be referenced via the implicit interface 'explicit_before_1'
54  external explicit_before_1
55  external implicit_before_1
56  !WARNING: The global subprogram 'explicit_func_before_1' should not be referenced via the implicit interface 'explicit_func_before_1'
57  external explicit_func_before_1
58  external implicit_func_before_1
59  !WARNING: The global entity 'module_after_1' corresponding to the local procedure 'module_after_1' is not a callable subprogram
60  external module_after_1
61  !WARNING: The global entity 'block_data_after_1' corresponding to the local procedure 'block_data_after_1' is not a callable subprogram
62  external block_data_after_1
63  !WARNING: The global subprogram 'explicit_after_1' should not be referenced via the implicit interface 'explicit_after_1'
64  external explicit_after_1
65  external implicit_after_1
66  !WARNING: The global subprogram 'explicit_func_after_1' should not be referenced via the implicit interface 'explicit_func_after_1'
67  external explicit_func_after_1
68  external implicit_func_after_1
69  call module_before_1
70  !ERROR: 'module_before_2' is not a callable procedure
71  call module_before_2
72  call block_data_before_1
73  !ERROR: 'block_data_before_2' is not a callable procedure
74  call block_data_before_2
75  call explicit_before_1(1.)
76  !ERROR: References to the procedure 'explicit_before_2' require an explicit interface
77  !BECAUSE: a dummy argument has the allocatable, asynchronous, optional, pointer, target, value, or volatile attribute
78  call explicit_before_2(1.)
79  !WARNING: If the procedure's interface were explicit, this reference would be in error
80  !BECAUSE: Dummy argument 'a=' (#1) is not OPTIONAL and is not associated with an actual argument in this procedure reference
81  call implicit_before_1
82  !WARNING: If the procedure's interface were explicit, this reference would be in error
83  !BECAUSE: Dummy argument 'a=' (#1) is not OPTIONAL and is not associated with an actual argument in this procedure reference
84  call implicit_before_2
85  print *, explicit_func_before_1(1.)
86  !ERROR: References to the procedure 'explicit_func_before_2' require an explicit interface
87  !BECAUSE: a dummy argument has the allocatable, asynchronous, optional, pointer, target, value, or volatile attribute
88  print *, explicit_func_before_2(1.)
89  !WARNING: If the procedure's interface were explicit, this reference would be in error
90  !BECAUSE: Dummy argument 'a=' (#1) is not OPTIONAL and is not associated with an actual argument in this procedure reference
91  print *, implicit_func_before_1()
92  !WARNING: If the procedure's interface were explicit, this reference would be in error
93  !BECAUSE: Dummy argument 'a=' (#1) is not OPTIONAL and is not associated with an actual argument in this procedure reference
94  print *, implicit_func_before_2()
95  call module_after_1
96  call module_after_2
97  call block_data_after_1
98  call block_data_after_2
99  call explicit_after_1(1.)
100  !ERROR: References to the procedure 'explicit_after_2' require an explicit interface
101  !BECAUSE: a dummy argument has the allocatable, asynchronous, optional, pointer, target, value, or volatile attribute
102  call explicit_after_2(1.)
103  !WARNING: If the procedure's interface were explicit, this reference would be in error
104  !BECAUSE: Dummy argument 'a=' (#1) is not OPTIONAL and is not associated with an actual argument in this procedure reference
105  call implicit_after_1
106  !WARNING: If the procedure's interface were explicit, this reference would be in error
107  !BECAUSE: Dummy argument 'a=' (#1) is not OPTIONAL and is not associated with an actual argument in this procedure reference
108  call implicit_after_2
109  print *, explicit_func_after_1(1.)
110  !ERROR: References to the procedure 'explicit_func_after_2' require an explicit interface
111  !BECAUSE: a dummy argument has the allocatable, asynchronous, optional, pointer, target, value, or volatile attribute
112  print *, explicit_func_after_2(1.)
113  !WARNING: If the procedure's interface were explicit, this reference would be in error
114  !BECAUSE: Dummy argument 'a=' (#1) is not OPTIONAL and is not associated with an actual argument in this procedure reference
115  print *, implicit_func_after_1()
116  !WARNING: If the procedure's interface were explicit, this reference would be in error
117  !BECAUSE: Dummy argument 'a=' (#1) is not OPTIONAL and is not associated with an actual argument in this procedure reference
118  print *, implicit_func_after_2()
119end program
120
121block data justfine
122end
123
124module module_after_1
125end
126
127!ERROR: 'module_after_2' is already declared in this scoping unit
128module module_after_2
129end
130
131block data block_data_after_1
132end
133
134!ERROR: BLOCK DATA 'block_data_after_2' has been called
135block data block_data_after_2
136end
137
138subroutine explicit_after_1(a)
139  real, optional :: a
140end
141
142subroutine explicit_after_2(a)
143  real, optional :: a
144end
145
146subroutine implicit_after_1(a)
147  real :: a
148end
149
150subroutine implicit_after_2(a)
151  real :: a
152end
153
154function explicit_func_after_1(a)
155  real, optional :: a
156end
157
158function explicit_func_after_2(a)
159  real, optional :: a
160end
161
162function implicit_func_after_1(a)
163  real :: a
164end
165
166function implicit_func_after_2(a)
167  real :: a
168end
169