xref: /llvm-project/flang/test/Lower/dummy-procedure-in-entry.f90 (revision f35f863a88f83332bef9605ef4cfe4f05c066efb)
1! Test dummy procedures that are not an argument in every entry.
2! This requires creating a mock value in the entries where it is
3! not an argument.
4! RUN: bbc -emit-fir -hlfir=false %s -o - | FileCheck %s
5
6subroutine dummy_with_iface()
7  interface
8    real function x()
9    end function
10  end interface
11  entry dummy_with_iface_entry(x)
12  call takes_real(x())
13end subroutine
14! CHECK-LABEL: func @_QPdummy_with_iface() {
15! CHECK:  %[[VAL_0:.*]] = fir.alloca f32 {adapt.valuebyref}
16! CHECK:  %[[VAL_1:.*]] = fir.undefined !fir.boxproc<() -> ()>
17! CHECK:  br ^bb1
18! CHECK:  ^bb1:
19! CHECK:  %[[VAL_2:.*]] = fir.box_addr %[[VAL_1]] : (!fir.boxproc<() -> ()>) -> (() -> f32)
20! CHECK:  %[[VAL_3:.*]] = fir.call %[[VAL_2]]() {{.*}}: () -> f32
21! CHECK:  fir.store %[[VAL_3]] to %[[VAL_0]] : !fir.ref<f32>
22! CHECK:  fir.call @_QPtakes_real(%[[VAL_0]]) {{.*}}: (!fir.ref<f32>) -> ()
23
24! CHECK-LABEL: func @_QPdummy_with_iface_entry(
25! CHECK-SAME:  %[[VAL_0:.*]]: !fir.boxproc<() -> ()>) {
26! CHECK:  %[[VAL_1:.*]] = fir.alloca f32 {adapt.valuebyref}
27! CHECK:  br ^bb1
28! CHECK:  ^bb1:
29! CHECK:  %[[VAL_2:.*]] = fir.box_addr %[[VAL_0]] : (!fir.boxproc<() -> ()>) -> (() -> f32)
30! CHECK:  %[[VAL_3:.*]] = fir.call %[[VAL_2]]() {{.*}}: () -> f32
31! CHECK:  fir.store %[[VAL_3]] to %[[VAL_1]] : !fir.ref<f32>
32! CHECK:  fir.call @_QPtakes_real(%[[VAL_1]]) {{.*}}: (!fir.ref<f32>) -> ()
33
34subroutine subroutine_dummy()
35  entry subroutine_dummy_entry(x)
36  call x()
37end subroutine
38! CHECK-LABEL: func @_QPsubroutine_dummy() {
39! CHECK:  %[[VAL_0:.*]] = fir.undefined !fir.boxproc<() -> ()>
40! CHECK:  br ^bb1
41! CHECK:  ^bb1:
42! CHECK:  %[[VAL_1:.*]] = fir.box_addr %[[VAL_0]] : (!fir.boxproc<() -> ()>) -> (() -> ())
43! CHECK:  fir.call %[[VAL_1]]() {{.*}}: () -> ()
44
45! CHECK-LABEL: func @_QPsubroutine_dummy_entry(
46! CHECK-SAME:  %[[VAL_0:.*]]: !fir.boxproc<() -> ()>) {
47! CHECK:  br ^bb1
48! CHECK:  ^bb1:
49! CHECK:  %[[VAL_1:.*]] = fir.box_addr %[[VAL_0]] : (!fir.boxproc<() -> ()>) -> (() -> ())
50! CHECK:  fir.call %[[VAL_1]]() {{.*}}: () -> ()
51