1 ! RUN: bbc -emit-fir %s -o - | FileCheck %s
3 ! Test procedure declarations. Change appearance order of definition and usages
4 ! (passing a procedure and calling it), with and without definitions.
5 ! Check that the definition type prevail if available and that casts are inserted to
6 ! accommodate for the signature mismatch in the different location due to implicit
7 ! typing rules and Fortran loose interface compatibility rule history.
10 ! Note: all the cases where their is a definition are exactly the same,
11 ! since definition should be processed first regardless.
14 ! CHECK-LABEL: func @_QPpass_foo() {
17 ! CHECK: %[[f:.*]] = fir.address_of(@_QPfoo)
18 ! CHECK: fir.emboxproc %[[f]] : ((!fir.ref<!fir.array<2x5xi32>>) -> ()) -> !fir.boxproc<() -> ()>
21 ! CHECK-LABEL: func @_QPcall_foo(
22 ! CHECK-SAME: %{{.*}}: !fir.ref<!fir.array<10xi32>>{{.*}}) {
23 subroutine call_foo(i
)
25 ! %[[argconvert:*]] = fir.convert %arg0 :
26 ! fir.call @_QPfoo(%[[argconvert]]) {{.*}}: (!fir.ref<!fir.array<2x5xi32>>) -> ()
29 ! CHECK-LABEL: func @_QPfoo(
30 ! CHECK-SAME: %{{.*}}: !fir.ref<!fir.array<2x5xi32>>{{.*}}) {
37 ! CHECK-LABEL: func @_QPcall_foo2(
38 ! CHECK-SAME: %{{.*}}: !fir.ref<!fir.array<10xi32>>{{.*}}) {
39 subroutine call_foo2(i
)
41 ! %[[argconvert:*]] = fir.convert %arg0 :
42 ! fir.call @_QPfoo2(%[[argconvert]]) {{.*}}: (!fir.ref<!fir.array<2x5xi32>>) -> ()
45 ! CHECK-LABEL: func @_QPpass_foo2() {
46 subroutine pass_foo2()
48 ! CHECK: %[[f:.*]] = fir.address_of(@_QPfoo2)
49 ! CHECK: fir.emboxproc %[[f]] : ((!fir.ref<!fir.array<2x5xi32>>) -> ()) -> !fir.boxproc<() -> ()>
52 ! CHECK-LABEL: func @_QPfoo2(
53 ! CHECK-SAME: %{{.*}}: !fir.ref<!fir.array<2x5xi32>>{{.*}}) {
60 ! CHECK-LABEL: func @_QPcall_foo3(
61 ! CHECK-SAME: %{{.*}}: !fir.ref<!fir.array<10xi32>>{{.*}}) {
62 subroutine call_foo3(i
)
64 ! %[[argconvert:*]] = fir.convert %arg0 :
65 ! fir.call @_QPfoo3(%[[argconvert]]) {{.*}}: (!fir.ref<!fir.array<2x5xi32>>) -> ()
68 ! CHECK-LABEL: func @_QPfoo3(
69 ! CHECK-SAME: %{{.*}}: !fir.ref<!fir.array<2x5xi32>>{{.*}}) {
74 ! CHECK-LABEL: func @_QPpass_foo3() {
75 subroutine pass_foo3()
77 ! CHECK: %[[f:.*]] = fir.address_of(@_QPfoo3)
78 ! CHECK: fir.emboxproc %[[f]] : ((!fir.ref<!fir.array<2x5xi32>>) -> ()) -> !fir.boxproc<() -> ()>
83 ! CHECK-LABEL: func @_QPfoo4(
84 ! CHECK-SAME: %{{.*}}: !fir.ref<!fir.array<2x5xi32>>{{.*}}) {
89 ! CHECK-LABEL: func @_QPcall_foo4(
90 ! CHECK-SAME: %{{.*}}: !fir.ref<!fir.array<10xi32>>{{.*}}) {
91 subroutine call_foo4(i
)
93 ! %[[argconvert:*]] = fir.convert %arg0 :
94 ! fir.call @_QPfoo4(%[[argconvert]]) {{.*}}: (!fir.ref<!fir.array<2x5xi32>>) -> ()
97 ! CHECK-LABEL: func @_QPpass_foo4() {
98 subroutine pass_foo4()
100 ! CHECK: %[[f:.*]] = fir.address_of(@_QPfoo4)
101 ! CHECK: fir.emboxproc %[[f]] : ((!fir.ref<!fir.array<2x5xi32>>) -> ()) -> !fir.boxproc<() -> ()>
106 ! CHECK-LABEL: func @_QPfoo5(
107 ! CHECK-SAME: %{{.*}}: !fir.ref<!fir.array<2x5xi32>>{{.*}}) {
112 ! CHECK-LABEL: func @_QPpass_foo5() {
113 subroutine pass_foo5()
115 ! CHECK: %[[f:.*]] = fir.address_of(@_QPfoo5)
116 ! CHECK: fir.emboxproc %[[f]] : ((!fir.ref<!fir.array<2x5xi32>>) -> ()) -> !fir.boxproc<() -> ()>
119 ! CHECK-LABEL: func @_QPcall_foo5(
120 ! CHECK-SAME: %{{.*}}: !fir.ref<!fir.array<10xi32>>{{.*}}) {
121 subroutine call_foo5(i
)
123 ! %[[argconvert:*]] = fir.convert %arg0 :
124 ! fir.call @_QPfoo5(%[[argconvert]]) {{.*}}: (!fir.ref<!fir.array<2x5xi32>>) -> ()
129 ! Test when there is no definition (declaration at the end of the mlir module)
130 ! First use gives the function type
133 ! CHECK-LABEL: func @_QPcall_foo6(
134 ! CHECK-SAME: %{{.*}}: !fir.ref<!fir.array<10xi32>>{{.*}}) {
135 subroutine call_foo6(i
)
140 ! CHECK-LABEL: func @_QPpass_foo6() {
141 subroutine pass_foo6()
143 ! CHECK: %[[f:.*]] = fir.address_of(@_QPfoo6) : (!fir.ref<!fir.array<10xi32>>) -> ()
144 ! CHECK: fir.emboxproc %[[f]] : ((!fir.ref<!fir.array<10xi32>>) -> ()) -> !fir.boxproc<() -> ()>
149 ! CHECK-LABEL: func @_QPpass_foo7() {
150 subroutine pass_foo7()
155 ! CHECK-LABEL: func @_QPcall_foo7(
156 ! CHECK-SAME: %{{.*}}: !fir.ref<!fir.array<10xi32>>{{.*}}) -> f32 {
157 function call_foo7(i
)
159 ! CHECK: %[[f:.*]] = fir.address_of(@_QPfoo7) : () -> ()
160 ! CHECK: %[[funccast:.*]] = fir.convert %[[f]] : (() -> ()) -> ((!fir.ref<!fir.array<10xi32>>) -> f32)
161 ! CHECK: fir.call %[[funccast]](%arg0) {{.*}}: (!fir.ref<!fir.array<10xi32>>) -> f32
166 ! call, call with different type
167 ! CHECK-LABEL: func @_QPcall_foo8(
168 ! CHECK-SAME: %{{.*}}: !fir.ref<!fir.array<10xi32>>{{.*}}) {
169 subroutine call_foo8(i
)
174 ! CHECK-LABEL: func @_QPcall_foo8_2(
175 ! CHECK-SAME: %{{.*}}: !fir.ref<!fir.array<2x5xi32>>{{.*}}) {
176 subroutine call_foo8_2(i
)
178 ! %[[argconvert:*]] = fir.convert %arg0 :
182 ! Test that target attribute is lowered in declaration of functions that are
183 ! not defined in this file.
184 ! CHECK-LABEL:func @_QPtest_target_in_iface
185 subroutine test_target_in_iface()
187 subroutine test_target(i
, x
)
194 ! CHECK: fir.call @_QPtest_target
195 call test_target(i
, x
)
198 ! CHECK: func private @_QPfoo6(!fir.ref<!fir.array<10xi32>>)
199 ! CHECK: func private @_QPfoo7()
201 ! Test declaration from test_target_in_iface
202 ! CHECK-LABEL: func private @_QPtest_target(!fir.ref<i32> {fir.target}, !fir.box<!fir.array<?xf32>> {fir.target})