1 ! Test questionable but existing abuses of implicit interfaces.
2 ! Lowering must close the eyes and do as if it did not know
3 ! about the function definition since semantic lets these
4 ! programs through with a warning.
5 ! RUN: bbc -emit-fir -hlfir %s -o - | FileCheck %s
7 subroutine takes_char(c
)
11 subroutine pass_real_to_char(r
)
15 ! CHECK-LABEL: func.func @_QPpass_real_to_char(
16 ! CHECK: %[[VAL_1:.*]]:2 = hlfir.declare {{.*}}Er
17 ! CHECK: %[[VAL_2:.*]] = fir.address_of(@_QPtakes_char) : (!fir.boxchar<1>) -> ()
18 ! CHECK: %[[VAL_3:.*]] = fir.convert %[[VAL_2]] : ((!fir.boxchar<1>) -> ()) -> ((!fir.ref<f64>) -> ())
19 ! CHECK: fir.call %[[VAL_3]](%[[VAL_1]]#1) {{.*}}: (!fir.ref<f64>) -> ()
21 subroutine pass_char_proc_to_char()
22 character(8), external :: char_proc
23 call takes_char(char_proc
)
25 ! CHECK: %[[VAL_0:.*]] = fir.address_of(@_QPchar_proc) : (!fir.ref<!fir.char<1,8>>, index) -> !fir.boxchar<1>
26 ! CHECK: %[[VAL_1:.*]] = arith.constant 8 : i64
27 ! CHECK: %[[VAL_2:.*]] = fir.emboxproc %[[VAL_0]] : ((!fir.ref<!fir.char<1,8>>, index) -> !fir.boxchar<1>) -> !fir.boxproc<() -> ()>
28 ! CHECK: %[[VAL_3:.*]] = fir.undefined tuple<!fir.boxproc<() -> ()>, i64>
29 ! CHECK: %[[VAL_4:.*]] = fir.insert_value %[[VAL_3]], %[[VAL_2]], [0 : index] : (tuple<!fir.boxproc<() -> ()>, i64>, !fir.boxproc<() -> ()>) -> tuple<!fir.boxproc<() -> ()>, i64>
30 ! CHECK: %[[VAL_5:.*]] = fir.insert_value %[[VAL_4]], %[[VAL_1]], [1 : index] : (tuple<!fir.boxproc<() -> ()>, i64>, i64) -> tuple<!fir.boxproc<() -> ()>, i64>
31 ! CHECK: %[[VAL_6:.*]] = fir.address_of(@_QPtakes_char) : (!fir.boxchar<1>) -> ()
32 ! CHECK: %[[VAL_7:.*]] = fir.convert %[[VAL_6]] : ((!fir.boxchar<1>) -> ()) -> ((tuple<!fir.boxproc<() -> ()>, i64>) -> ())
33 ! CHECK: fir.call %[[VAL_7]](%[[VAL_5]]) {{.*}}: (tuple<!fir.boxproc<() -> ()>, i64>) -> ()
35 subroutine pass_kind2_char_to_char(c
)
36 character(4, kind
=2) :: c
39 ! CHECK-LABEL: func.func @_QPpass_kind2_char_to_char(
40 ! CHECK: %[[VAL_3:.*]]:2 = hlfir.declare {{.*}}Ec
41 ! CHECK: %[[VAL_4:.*]] = fir.address_of(@_QPtakes_char) : (!fir.boxchar<1>) -> ()
42 ! CHECK: %[[VAL_5:.*]] = fir.convert %[[VAL_4]] : ((!fir.boxchar<1>) -> ()) -> ((!fir.boxchar<2>) -> ())
43 ! CHECK: fir.call %[[VAL_5]](%[[VAL_3]]#0) {{.*}}: (!fir.boxchar<2>) -> ()
45 subroutine takes_real(r
)
49 subroutine pass_int_to_real(i
)
53 ! CHECK-LABEL: func.func @_QPpass_int_to_real(
54 ! CHECK: %[[VAL_1:.*]]:2 = hlfir.declare {{.*}}Ei
55 ! CHECK: %[[VAL_2:.*]] = fir.convert %[[VAL_1]]#1 : (!fir.ref<i64>) -> !fir.ref<f64>
56 ! CHECK: fir.call @_QPtakes_real(%[[VAL_2]]) {{.*}}: (!fir.ref<f64>) -> ()
58 subroutine pass_char_to_real(c
)
62 ! CHECK-LABEL: func.func @_QPpass_char_to_real(
63 ! CHECK: %[[VAL_3:.*]]:2 = hlfir.declare {{.*}}Ec
64 ! CHECK: %[[VAL_4:.*]] = fir.address_of(@_QPtakes_real) : (!fir.ref<f64>) -> ()
65 ! CHECK: %[[VAL_5:.*]] = fir.convert %[[VAL_4]] : ((!fir.ref<f64>) -> ()) -> ((!fir.boxchar<1>) -> ())
66 ! CHECK: fir.call %[[VAL_5]](%[[VAL_3]]#0) {{.*}}: (!fir.boxchar<1>) -> ()
68 subroutine pass_proc_to_real()
69 real(8), external :: proc
72 ! CHECK-LABEL: func.func @_QPpass_proc_to_real() {
73 ! CHECK: %[[VAL_0:.*]] = fir.address_of(@_QPproc) : () -> f64
74 ! CHECK: %[[VAL_1:.*]] = fir.emboxproc %[[VAL_0]] : (() -> f64) -> !fir.boxproc<() -> ()>
75 ! CHECK: %[[VAL_2:.*]] = fir.address_of(@_QPtakes_real) : (!fir.ref<f64>) -> ()
76 ! CHECK: %[[VAL_3:.*]] = fir.convert %[[VAL_2]] : ((!fir.ref<f64>) -> ()) -> ((!fir.boxproc<() -> ()>) -> ())
77 ! CHECK: fir.call %[[VAL_3]](%[[VAL_1]]) {{.*}}: (!fir.boxproc<() -> ()>) -> ()
79 subroutine pass_complex_to_real(cmplx
)
81 call takes_real(cmplx
)
83 ! CHECK-LABEL: func.func @_QPpass_complex_to_real(
84 ! CHECK: %[[VAL_1:.*]]:2 = hlfir.declare {{.*}}Ecmplx
85 ! CHECK: %[[VAL_2:.*]] = fir.convert %[[VAL_1]]#1 : (!fir.ref<!fir.complex<4>>) -> !fir.ref<f64>
86 ! CHECK: fir.call @_QPtakes_real(%[[VAL_2]]) {{.*}}: (!fir.ref<f64>) -> ()
88 subroutine takes_char_proc(c
)
89 character(8), external :: c
92 subroutine pass_proc_to_char_proc()
94 call takes_char_proc(proc
)
96 ! CHECK-LABEL: func.func @_QPpass_proc_to_char_proc() {
97 ! CHECK: %[[VAL_0:.*]] = fir.address_of(@_QPproc) : () -> f64
98 ! CHECK: %[[VAL_1:.*]] = fir.emboxproc %[[VAL_0]] : (() -> f64) -> !fir.boxproc<() -> ()>
99 ! CHECK: %[[VAL_2:.*]] = fir.address_of(@_QPtakes_char_proc) : (tuple<!fir.boxproc<() -> ()>, i64>) -> ()
100 ! CHECK: %[[VAL_3:.*]] = fir.convert %[[VAL_2]] : ((tuple<!fir.boxproc<() -> ()>, i64>) -> ()) -> ((!fir.boxproc<() -> ()>) -> ())
101 ! CHECK: fir.call %[[VAL_3]](%[[VAL_1]]) {{.*}}: (!fir.boxproc<() -> ()>) -> ()
103 subroutine pass_char_to_char_proc(c
)
105 call takes_char_proc(c
)
107 ! CHECK-LABEL: func.func @_QPpass_char_to_char_proc(
108 ! CHECK: %[[VAL_3:.*]]:2 = hlfir.declare {{.*}}Ec
109 ! CHECK: %[[VAL_4:.*]] = fir.address_of(@_QPtakes_char_proc) : (tuple<!fir.boxproc<() -> ()>, i64>) -> ()
110 ! CHECK: %[[VAL_5:.*]] = fir.convert %[[VAL_4]] : ((tuple<!fir.boxproc<() -> ()>, i64>) -> ()) -> ((!fir.boxchar<1>) -> ())
111 ! CHECK: fir.call %[[VAL_5]](%[[VAL_3]]#0) {{.*}}: (!fir.boxchar<1>) -> ()
113 subroutine takes_proc(proc
)
114 real(8), external :: proc
117 subroutine pass_char_proc_to_proc()
118 character(8), external :: char_proc
119 call takes_proc(char_proc
)
121 ! CHECK-LABEL: func.func @_QPpass_char_proc_to_proc() {
122 ! CHECK: %[[VAL_0:.*]] = fir.address_of(@_QPchar_proc) : (!fir.ref<!fir.char<1,8>>, index) -> !fir.boxchar<1>
123 ! CHECK: %[[VAL_1:.*]] = arith.constant 8 : i64
124 ! CHECK: %[[VAL_2:.*]] = fir.emboxproc %[[VAL_0]] : ((!fir.ref<!fir.char<1,8>>, index) -> !fir.boxchar<1>) -> !fir.boxproc<() -> ()>
125 ! CHECK: %[[VAL_3:.*]] = fir.undefined tuple<!fir.boxproc<() -> ()>, i64>
126 ! CHECK: %[[VAL_4:.*]] = fir.insert_value %[[VAL_3]], %[[VAL_2]], [0 : index] : (tuple<!fir.boxproc<() -> ()>, i64>, !fir.boxproc<() -> ()>) -> tuple<!fir.boxproc<() -> ()>, i64>
127 ! CHECK: %[[VAL_5:.*]] = fir.insert_value %[[VAL_4]], %[[VAL_1]], [1 : index] : (tuple<!fir.boxproc<() -> ()>, i64>, i64) -> tuple<!fir.boxproc<() -> ()>, i64>
128 ! CHECK: %[[VAL_6:.*]] = fir.address_of(@_QPtakes_proc) : (!fir.boxproc<() -> ()>) -> ()
129 ! CHECK: %[[VAL_7:.*]] = fir.convert %[[VAL_6]] : ((!fir.boxproc<() -> ()>) -> ()) -> ((tuple<!fir.boxproc<() -> ()>, i64>) -> ())
130 ! CHECK: fir.call %[[VAL_7]](%[[VAL_5]]) {{.*}}: (tuple<!fir.boxproc<() -> ()>, i64>) -> ()
132 subroutine pass_real_to_proc(r
)
136 ! CHECK-LABEL: func.func @_QPpass_real_to_proc(
137 ! CHECK: %[[VAL_1:.*]]:2 = hlfir.declare {{.*}}Er
138 ! CHECK: %[[VAL_2:.*]] = fir.address_of(@_QPtakes_proc) : (!fir.boxproc<() -> ()>) -> ()
139 ! CHECK: %[[VAL_3:.*]] = fir.convert %[[VAL_2]] : ((!fir.boxproc<() -> ()>) -> ()) -> ((!fir.ref<f64>) -> ())
140 ! CHECK: fir.call %[[VAL_3]](%[[VAL_1]]#1) {{.*}}: (!fir.ref<f64>) -> ()
142 subroutine pass_too_many_args()
143 call takes_real(I
, Kown
, what
, I
, am
, doing
)
145 ! CHECK-LABEL: func.func @_QPpass_too_many_args() {
146 ! CHECK: %[[VAL_10:.*]] = fir.address_of(@_QPtakes_real) : (!fir.ref<f64>) -> ()
147 ! CHECK: %[[VAL_11:.*]] = fir.convert %[[VAL_10]] : ((!fir.ref<f64>) -> ()) -> ((!fir.ref<i32>, !fir.ref<i32>, !fir.ref<f32>, !fir.ref<i32>, !fir.ref<f32>, !fir.ref<f32>) -> ())
148 ! CHECK: fir.call %[[VAL_11]](%{{.*}}, %{{.*}}, %{{.*}}, %{{.*}}, %{{.*}}, %{{.*}}) {{.*}}: (!fir.ref<i32>, !fir.ref<i32>, !fir.ref<f32>, !fir.ref<i32>, !fir.ref<f32>, !fir.ref<f32>) -> ()
150 subroutine pass_too_few_args()
153 ! CHECK-LABEL: func.func @_QPpass_too_few_args() {
154 ! CHECK: %[[VAL_0:.*]] = fir.address_of(@_QPtakes_real) : (!fir.ref<f64>) -> ()
155 ! CHECK: %[[VAL_1:.*]] = fir.convert %[[VAL_0]] : ((!fir.ref<f64>) -> ()) -> (() -> ())
156 ! CHECK: fir.call %[[VAL_1]]() {{.*}}: () -> ()