| 1 |
! RUN: bbc -emit-hlfir %s -o - | FileCheck %s |
| 2 |
|
| 3 |
! Tests the different possible type involving polymorphic entities. |
| 4 |
|
| 5 |
module call_dispatch |
| 6 |
|
| 7 |
interface |
| 8 |
subroutine nopass_defferred(x) |
| 9 |
real :: x(:) |
| 10 |
end subroutine |
| 11 |
end interface |
| 12 |
|
| 13 |
type p1 |
| 14 |
integer :: a |
| 15 |
integer :: b |
| 16 |
contains |
| 17 |
procedure, nopass :: tbp_nopass |
| 18 |
procedure :: tbp_pass |
| 19 |
procedure, pass(this) :: tbp_pass_arg0 |
| 20 |
procedure, pass(this) :: tbp_pass_arg1 |
| 21 |
|
| 22 |
procedure, nopass :: proc1 => p1_proc1_nopass |
| 23 |
procedure :: proc2 => p1_proc2 |
| 24 |
procedure, pass(this) :: proc3 => p1_proc3_arg0 |
| 25 |
procedure, pass(this) :: proc4 => p1_proc4_arg1 |
| 26 |
|
| 27 |
procedure, nopass :: p1_fct1_nopass |
| 28 |
procedure :: p1_fct2 |
| 29 |
procedure, pass(this) :: p1_fct3_arg0 |
| 30 |
procedure, pass(this) :: p1_fct4_arg1 |
| 31 |
|
| 32 |
procedure :: pass_with_class_arg |
| 33 |
end type |
| 34 |
|
| 35 |
type, abstract :: a1 |
| 36 |
real :: a |
| 37 |
real :: b |
| 38 |
contains |
| 39 |
procedure(nopass_defferred), deferred, nopass :: nopassd |
| 40 |
end type |
| 41 |
|
| 42 |
type :: node |
| 43 |
type(node_ptr), pointer :: n(:) |
| 44 |
end type |
| 45 |
type :: use_node |
| 46 |
type(node) :: n |
| 47 |
end type |
| 48 |
type :: node_ptr |
| 49 |
type(node_ptr), pointer :: n |
| 50 |
end type |
| 51 |
|
| 52 |
type :: q1 |
| 53 |
class(p1), allocatable :: p |
| 54 |
end type |
| 55 |
|
| 56 |
contains |
| 57 |
|
| 58 |
! ------------------------------------------------------------------------------ |
| 59 |
! Test lowering of type-bound procedure call on polymorphic entities |
| 60 |
! ------------------------------------------------------------------------------ |
| 61 |
|
| 62 |
function p1_fct1_nopass() |
| 63 |
real :: p1_fct1_nopass |
| 64 |
end function |
| 65 |
! CHECK-LABEL: func.func @_QMcall_dispatchPp1_fct1_nopass() -> f32 |
| 66 |
|
| 67 |
function p1_fct2(p) |
| 68 |
real :: p1_fct2 |
| 69 |
class(p1) :: p |
| 70 |
end function |
| 71 |
! CHECK-LABEL: func.func @_QMcall_dispatchPp1_fct2(%{{.*}}: !fir.class<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>) -> f32 |
| 72 |
|
| 73 |
function p1_fct3_arg0(this) |
| 74 |
real :: p1_fct2 |
| 75 |
class(p1) :: this |
| 76 |
end function |
| 77 |
! CHECK-LABEL: func.func @_QMcall_dispatchPp1_fct3_arg0(%{{.*}}: !fir.class<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>) -> f32 |
| 78 |
|
| 79 |
function p1_fct4_arg1(i, this) |
| 80 |
real :: p1_fct2 |
| 81 |
integer :: i |
| 82 |
class(p1) :: this |
| 83 |
end function |
| 84 |
! CHECK-LABEL: func.func @_QMcall_dispatchPp1_fct4_arg1(%{{.*}}: !fir.ref<i32>, %{{.*}}: !fir.class<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>) -> f32 |
| 85 |
|
| 86 |
subroutine pass_with_class_arg(this, other) |
| 87 |
class(p1) :: this |
| 88 |
class(p1) :: other |
| 89 |
end subroutine |
| 90 |
! CHECK-LABEL: func.func @_QMcall_dispatchPpass_with_class_arg(%{{.*}}: !fir.class<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>, %{{.*}}: !fir.class<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>) { |
| 91 |
|
| 92 |
subroutine p1_proc1_nopass() |
| 93 |
end subroutine |
| 94 |
! CHECK-LABEL: func.func @_QMcall_dispatchPp1_proc1_nopass() |
| 95 |
|
| 96 |
subroutine p1_proc2(p) |
| 97 |
class(p1) :: p |
| 98 |
end subroutine |
| 99 |
! CHECK-LABEL: func.func @_QMcall_dispatchPp1_proc2(%{{.*}}: !fir.class<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>) |
| 100 |
|
| 101 |
subroutine p1_proc3_arg0(this) |
| 102 |
class(p1) :: this |
| 103 |
end subroutine |
| 104 |
! CHECK-LABEL: func.func @_QMcall_dispatchPp1_proc3_arg0(%{{.*}}: !fir.class<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>) |
| 105 |
|
| 106 |
subroutine p1_proc4_arg1(i, this) |
| 107 |
integer, intent(in) :: i |
| 108 |
class(p1) :: this |
| 109 |
end subroutine |
| 110 |
! CHECK-LABEL: func.func @_QMcall_dispatchPp1_proc4_arg1(%{{.*}}: !fir.ref<i32>, %{{.*}}: !fir.class<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>) |
| 111 |
|
| 112 |
subroutine tbp_nopass() |
| 113 |
end subroutine |
| 114 |
! CHECK-LABEL: func.func @_QMcall_dispatchPtbp_nopass() |
| 115 |
|
| 116 |
subroutine tbp_pass(t) |
| 117 |
class(p1) :: t |
| 118 |
end subroutine |
| 119 |
! CHECK-LABEL: func.func @_QMcall_dispatchPtbp_pass(%{{.*}}: !fir.class<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>) |
| 120 |
|
| 121 |
subroutine tbp_pass_arg0(this) |
| 122 |
class(p1) :: this |
| 123 |
end subroutine |
| 124 |
! CHECK-LABEL: func.func @_QMcall_dispatchPtbp_pass_arg0(%{{.*}}: !fir.class<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>) |
| 125 |
|
| 126 |
subroutine tbp_pass_arg1(i, this) |
| 127 |
integer, intent(in) :: i |
| 128 |
class(p1) :: this |
| 129 |
end subroutine |
| 130 |
! CHECK-LABEL: func.func @_QMcall_dispatchPtbp_pass_arg1(%{{.*}}: !fir.ref<i32>, %{{.*}}: !fir.class<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>) |
| 131 |
|
| 132 |
subroutine check_dispatch(p) |
| 133 |
class(p1) :: p |
| 134 |
real :: a |
| 135 |
|
| 136 |
call p%tbp_nopass() |
| 137 |
call p%tbp_pass() |
| 138 |
call p%tbp_pass_arg0() |
| 139 |
call p%tbp_pass_arg1(1) |
| 140 |
|
| 141 |
call p%proc1() |
| 142 |
call p%proc2() |
| 143 |
call p%proc3() |
| 144 |
call p%proc4(1) |
| 145 |
|
| 146 |
a = p%p1_fct1_nopass() |
| 147 |
a = p%p1_fct2() |
| 148 |
a = p%p1_fct3_arg0() |
| 149 |
a = p%p1_fct4_arg1(1) |
| 150 |
end subroutine |
| 151 |
|
| 152 |
! CHECK-LABEL: func.func @_QMcall_dispatchPcheck_dispatch( |
| 153 |
! CHECK-SAME: %[[P:.*]]: !fir.class<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>> {fir.bindc_name = "p"}) { |
| 154 |
! CHECK: %[[P_DECL:.*]]:2 = hlfir.declare %[[P]] dummy_scope %{{[0-9]+}} {uniq_name = "_QMcall_dispatchFcheck_dispatchEp"} : (!fir.class<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>, !fir.dscope) -> (!fir.class<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>, !fir.class<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>) |
| 155 |
! CHECK: fir.dispatch "tbp_nopass"(%[[P_DECL]]#1 : !fir.class<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>){{$}} |
| 156 |
! CHECK: fir.dispatch "tbp_pass"(%[[P_DECL]]#0 : !fir.class<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>) (%[[P_DECL]]#0 : !fir.class<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>) {pass_arg_pos = 0 : i32} |
| 157 |
! CHECK: fir.dispatch "tbp_pass_arg0"(%[[P_DECL]]#0 : !fir.class<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>) (%[[P_DECL]]#0 : !fir.class<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>) {pass_arg_pos = 0 : i32} |
| 158 |
! CHECK: fir.dispatch "tbp_pass_arg1"(%[[P_DECL]]#0 : !fir.class<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>) (%{{.*}}, %[[P_DECL]]#0 : !fir.ref<i32>, !fir.class<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>) {pass_arg_pos = 1 : i32} |
| 159 |
|
| 160 |
! CHECK: fir.dispatch "proc1"(%[[P_DECL]]#1 : !fir.class<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>){{$}} |
| 161 |
! CHECK: fir.dispatch "proc2"(%[[P_DECL]]#0 : !fir.class<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>) (%[[P_DECL]]#0 : !fir.class<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>) {pass_arg_pos = 0 : i32} |
| 162 |
! CHECK: fir.dispatch "proc3"(%[[P_DECL]]#0 : !fir.class<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>) (%[[P_DECL]]#0 : !fir.class<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>) {pass_arg_pos = 0 : i32} |
| 163 |
! CHECK: fir.dispatch "proc4"(%[[P_DECL]]#0 : !fir.class<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>) (%{{.*}}, %[[P_DECL]]#0 : !fir.ref<i32>, !fir.class<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>) {pass_arg_pos = 1 : i32} |
| 164 |
|
| 165 |
! CHECK: %{{.*}} = fir.dispatch "p1_fct1_nopass"(%[[P_DECL]]#1 : !fir.class<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>) -> f32{{$}} |
| 166 |
! CHECK: %{{.*}} = fir.dispatch "p1_fct2"(%[[P_DECL]]#0 : !fir.class<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>) (%[[P_DECL]]#0 : !fir.class<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>) -> f32 {pass_arg_pos = 0 : i32} |
| 167 |
! CHECK: %{{.*}} = fir.dispatch "p1_fct3_arg0"(%[[P_DECL]]#0 : !fir.class<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>) (%[[P_DECL]]#0 : !fir.class<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>) -> f32 {pass_arg_pos = 0 : i32} |
| 168 |
! CHECK: %{{.*}} = fir.dispatch "p1_fct4_arg1"(%[[P_DECL]]#0 : !fir.class<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>) (%{{.*}}, %[[P_DECL]]#0 : !fir.ref<i32>, !fir.class<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>) -> f32 {pass_arg_pos = 1 : i32} |
| 169 |
|
| 170 |
subroutine check_dispatch_deferred(a, x) |
| 171 |
class(a1) :: a |
| 172 |
real :: x(:) |
| 173 |
call a%nopassd(x) |
| 174 |
end subroutine |
| 175 |
|
| 176 |
! CHECK-LABEL: func.func @_QMcall_dispatchPcheck_dispatch_deferred( |
| 177 |
! CHECK-SAME: %[[ARG0:.*]]: !fir.class<!fir.type<_QMcall_dispatchTa1{a:f32,b:f32}>> {fir.bindc_name = "a"}, |
| 178 |
! CHECK-SAME: %[[ARG1:.*]]: !fir.box<!fir.array<?xf32>> {fir.bindc_name = "x"}) { |
| 179 |
! CHECK: %[[ARG0_DECL:.*]]:2 = hlfir.declare %[[ARG0]] dummy_scope %{{[0-9]+}} {uniq_name = "_QMcall_dispatchFcheck_dispatch_deferredEa"} : (!fir.class<!fir.type<_QMcall_dispatchTa1{a:f32,b:f32}>>, !fir.dscope) -> (!fir.class<!fir.type<_QMcall_dispatchTa1{a:f32,b:f32}>>, !fir.class<!fir.type<_QMcall_dispatchTa1{a:f32,b:f32}>>) |
| 180 |
! CHECK: %[[ARG1_DECL:.*]]:2 = hlfir.declare %[[ARG1]] dummy_scope %{{[0-9]+}} {uniq_name = "_QMcall_dispatchFcheck_dispatch_deferredEx"} : (!fir.box<!fir.array<?xf32>>, !fir.dscope) -> (!fir.box<!fir.array<?xf32>>, !fir.box<!fir.array<?xf32>>) |
| 181 |
! CHECK: fir.dispatch "nopassd"(%[[ARG0_DECL]]#1 : !fir.class<!fir.type<_QMcall_dispatchTa1{a:f32,b:f32}>>) (%[[ARG1_DECL]]#0 : !fir.box<!fir.array<?xf32>>) |
| 182 |
|
| 183 |
subroutine check_dispatch_scalar_allocatable(p) |
| 184 |
class(p1), allocatable :: p |
| 185 |
call p%tbp_pass() |
| 186 |
end subroutine |
| 187 |
|
| 188 |
! CHECK-LABEL: func.func @_QMcall_dispatchPcheck_dispatch_scalar_allocatable( |
| 189 |
! CHECK-SAME: %[[ARG0:.*]]: !fir.ref<!fir.class<!fir.heap<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>>> {fir.bindc_name = "p"}) { |
| 190 |
! CHECK: %[[ARG0_DECL:.*]]:2 = hlfir.declare %[[ARG0]] dummy_scope %{{[0-9]+}} {fortran_attrs = #fir.var_attrs<allocatable>, uniq_name = "_QMcall_dispatchFcheck_dispatch_scalar_allocatableEp"} : (!fir.ref<!fir.class<!fir.heap<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>>>, !fir.dscope) -> (!fir.ref<!fir.class<!fir.heap<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>>>, !fir.ref<!fir.class<!fir.heap<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>>>) |
| 191 |
! CHECK: %[[LOAD:.*]] = fir.load %[[ARG0_DECL]]#0 : !fir.ref<!fir.class<!fir.heap<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>>> |
| 192 |
! CHECK: %[[REBOX:.*]] = fir.rebox %[[LOAD]] : (!fir.class<!fir.heap<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>>) -> !fir.class<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>> |
| 193 |
! CHECK: fir.dispatch "tbp_pass"(%[[REBOX]] : !fir.class<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>) (%[[REBOX]] : !fir.class<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>) {pass_arg_pos = 0 : i32} |
| 194 |
|
| 195 |
subroutine check_dispatch_scalar_pointer(p) |
| 196 |
class(p1), pointer :: p |
| 197 |
call p%tbp_pass() |
| 198 |
end subroutine |
| 199 |
|
| 200 |
! CHECK-LABEL: func.func @_QMcall_dispatchPcheck_dispatch_scalar_pointer( |
| 201 |
! CHECK-SAME: %[[ARG0:.*]]: !fir.ref<!fir.class<!fir.ptr<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>>> {fir.bindc_name = "p"}) { |
| 202 |
! CHECK: %[[ARG0_DECL:.*]]:2 = hlfir.declare %[[ARG0]] dummy_scope %{{[0-9]+}} {fortran_attrs = #fir.var_attrs<pointer>, uniq_name = "_QMcall_dispatchFcheck_dispatch_scalar_pointerEp"} : (!fir.ref<!fir.class<!fir.ptr<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>>>, !fir.dscope) -> (!fir.ref<!fir.class<!fir.ptr<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>>>, !fir.ref<!fir.class<!fir.ptr<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>>>) |
| 203 |
! CHECK: %[[LOAD:.*]] = fir.load %[[ARG0_DECL]]#0 : !fir.ref<!fir.class<!fir.ptr<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>>> |
| 204 |
! CHECK: %[[REBOX:.*]] = fir.rebox %[[LOAD]] : (!fir.class<!fir.ptr<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>>) -> !fir.class<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>> |
| 205 |
! CHECK: fir.dispatch "tbp_pass"(%[[REBOX]] : !fir.class<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>) (%[[REBOX]] : !fir.class<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>) {pass_arg_pos = 0 : i32} |
| 206 |
|
| 207 |
subroutine check_dispatch_static_array(p, t) |
| 208 |
class(p1) :: p(10) |
| 209 |
type(p1) :: t(10) |
| 210 |
integer :: i |
| 211 |
do i = 1, 10 |
| 212 |
call p(i)%tbp_pass() |
| 213 |
end do |
| 214 |
|
| 215 |
do i = 1, 10 |
| 216 |
call t(i)%tbp_pass() |
| 217 |
end do |
| 218 |
end subroutine |
| 219 |
|
| 220 |
! CHECK-LABEL: func.func @_QMcall_dispatchPcheck_dispatch_static_array( |
| 221 |
! CHECK-SAME: %[[ARG0:.*]]: !fir.class<!fir.array<10x!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>> {fir.bindc_name = "p"}, |
| 222 |
! CHECK-SAME: %[[ARG1:.*]]: !fir.ref<!fir.array<10x!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>> {fir.bindc_name = "t"}) { |
| 223 |
! CHECK: %[[ARG0_DECL:.*]]:2 = hlfir.declare %[[ARG0]] dummy_scope %{{[0-9]+}} {uniq_name = "_QMcall_dispatchFcheck_dispatch_static_arrayEp"} : (!fir.class<!fir.array<10x!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>>, !fir.dscope) -> (!fir.class<!fir.array<10x!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>>, !fir.class<!fir.array<10x!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>>) |
| 224 |
! CHECK: %[[ARG1_DECL:.*]]:2 = hlfir.declare %[[ARG1]](%{{.*}}) dummy_scope %{{[0-9]+}} {uniq_name = "_QMcall_dispatchFcheck_dispatch_static_arrayEt"} : (!fir.ref<!fir.array<10x!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>>, !fir.shape<1>, !fir.dscope) -> (!fir.ref<!fir.array<10x!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>>, !fir.ref<!fir.array<10x!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>>) |
| 225 |
! CHECK: fir.do_loop {{.*}} { |
| 226 |
! CHECK: %[[DESIGNATE:.*]] = hlfir.designate %[[ARG0_DECL]]#0 (%{{.*}}) : (!fir.class<!fir.array<10x!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>>, i64) -> !fir.class<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>> |
| 227 |
! CHECK: fir.dispatch "tbp_pass"(%[[DESIGNATE]] : !fir.class<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>) (%[[DESIGNATE]] : !fir.class<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>) {pass_arg_pos = 0 : i32} |
| 228 |
|
| 229 |
! CHECK: fir.do_loop {{.*}} { |
| 230 |
! CHECK: %[[DESIGNATE:.*]] = hlfir.designate %[[ARG1_DECL]]#0 (%{{.*}}) : (!fir.ref<!fir.array<10x!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>>, i64) -> !fir.ref<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>> |
| 231 |
! CHECK: %[[EMBOX:.*]] = fir.embox %[[DESIGNATE]] : (!fir.ref<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>) -> !fir.box<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>> |
| 232 |
! CHECK: %[[CONV:.*]] = fir.convert %[[EMBOX]] : (!fir.box<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>) -> !fir.class<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>> |
| 233 |
! CHECK: fir.call @_QMcall_dispatchPtbp_pass(%[[CONV]]) {{.*}}: (!fir.class<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>) -> () |
| 234 |
|
| 235 |
subroutine check_dispatch_dynamic_array(p, t) |
| 236 |
class(p1) :: p(:) |
| 237 |
type(p1) :: t(:) |
| 238 |
integer :: i |
| 239 |
do i = 1, 10 |
| 240 |
call p(i)%tbp_pass() |
| 241 |
end do |
| 242 |
|
| 243 |
do i = 1, 10 |
| 244 |
call t(i)%tbp_pass() |
| 245 |
end do |
| 246 |
end subroutine |
| 247 |
|
| 248 |
! CHECK-LABEL: func.func @_QMcall_dispatchPcheck_dispatch_dynamic_array( |
| 249 |
! CHECK-SAME: %[[ARG0:.*]]: !fir.class<!fir.array<?x!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>> {fir.bindc_name = "p"}, |
| 250 |
! CHECK-SAME: %[[ARG1:.*]]: !fir.box<!fir.array<?x!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>> {fir.bindc_name = "t"}) { |
| 251 |
! CHECK: %[[ARG0_DECL:.*]]:2 = hlfir.declare %[[ARG0]] dummy_scope %{{[0-9]+}} {uniq_name = "_QMcall_dispatchFcheck_dispatch_dynamic_arrayEp"} : (!fir.class<!fir.array<?x!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>>, !fir.dscope) -> (!fir.class<!fir.array<?x!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>>, !fir.class<!fir.array<?x!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>>) |
| 252 |
! CHECK: %[[ARG1_DECL:.*]]:2 = hlfir.declare %[[ARG1]] dummy_scope %{{[0-9]+}} {uniq_name = "_QMcall_dispatchFcheck_dispatch_dynamic_arrayEt"} : (!fir.box<!fir.array<?x!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>>, !fir.dscope) -> (!fir.box<!fir.array<?x!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>>, !fir.box<!fir.array<?x!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>>) |
| 253 |
! CHECK: %{{.*}} = fir.do_loop {{.*}} { |
| 254 |
! CHECK: %[[DESIGNATE:.*]] = hlfir.designate %[[ARG0_DECL]]#0 (%{{.*}}) : (!fir.class<!fir.array<?x!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>>, i64) -> !fir.class<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>> |
| 255 |
! CHECK: fir.dispatch "tbp_pass"(%[[DESIGNATE]] : !fir.class<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>) (%[[DESIGNATE]] : !fir.class<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>) {pass_arg_pos = 0 : i32} |
| 256 |
|
| 257 |
! CHECK: %{{.*}} = fir.do_loop {{.*}} { |
| 258 |
! CHECK: %[[DESIGNATE:.*]] = hlfir.designate %[[ARG1_DECL]]#0 (%{{.*}}) : (!fir.box<!fir.array<?x!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>>, i64) -> !fir.ref<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>> |
| 259 |
! CHECK: %[[EMBOX:.*]] = fir.embox %[[DESIGNATE]] : (!fir.ref<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>) -> !fir.box<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>> |
| 260 |
! CHECK: %[[CONV:.*]] = fir.convert %[[EMBOX]] : (!fir.box<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>) -> !fir.class<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>> |
| 261 |
! CHECK: fir.call @_QMcall_dispatchPtbp_pass(%[[CONV]]) {{.*}} : (!fir.class<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>) -> () |
| 262 |
|
| 263 |
subroutine check_dispatch_allocatable_array(p, t) |
| 264 |
class(p1), allocatable :: p(:) |
| 265 |
type(p1), allocatable :: t(:) |
| 266 |
integer :: i |
| 267 |
do i = 1, 10 |
| 268 |
call p(i)%tbp_pass() |
| 269 |
end do |
| 270 |
|
| 271 |
do i = 1, 10 |
| 272 |
call t(i)%tbp_pass() |
| 273 |
end do |
| 274 |
end subroutine |
| 275 |
|
| 276 |
! CHECK-LABEL: func.func @_QMcall_dispatchPcheck_dispatch_allocatable_array( |
| 277 |
! CHECK-SAME: %[[ARG0:.*]]: !fir.ref<!fir.class<!fir.heap<!fir.array<?x!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>>>> {fir.bindc_name = "p"}, |
| 278 |
! CHECK-SAME: %[[ARG1:.*]]: !fir.ref<!fir.box<!fir.heap<!fir.array<?x!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>>>> {fir.bindc_name = "t"}) { |
| 279 |
! CHECK: %[[ARG0_DECL:.*]]:2 = hlfir.declare %[[ARG0]] dummy_scope %{{[0-9]+}} {fortran_attrs = #fir.var_attrs<allocatable>, uniq_name = "_QMcall_dispatchFcheck_dispatch_allocatable_arrayEp"} : (!fir.ref<!fir.class<!fir.heap<!fir.array<?x!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>>>>, !fir.dscope) -> (!fir.ref<!fir.class<!fir.heap<!fir.array<?x!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>>>>, !fir.ref<!fir.class<!fir.heap<!fir.array<?x!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>>>>) |
| 280 |
! CHECK: %[[ARG1_DECL:.*]]:2 = hlfir.declare %[[ARG1]] dummy_scope %{{[0-9]+}} {fortran_attrs = #fir.var_attrs<allocatable>, uniq_name = "_QMcall_dispatchFcheck_dispatch_allocatable_arrayEt"} : (!fir.ref<!fir.box<!fir.heap<!fir.array<?x!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>>>>, !fir.dscope) -> (!fir.ref<!fir.box<!fir.heap<!fir.array<?x!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>>>>, !fir.ref<!fir.box<!fir.heap<!fir.array<?x!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>>>>) |
| 281 |
! CHECK: %{{.*}} = fir.do_loop {{.*}} { |
| 282 |
! CHECK: %[[LOAD_ARG0:.*]] = fir.load %[[ARG0_DECL]]#0 : !fir.ref<!fir.class<!fir.heap<!fir.array<?x!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>>>> |
| 283 |
! CHECK: %[[DESIGNATE:.*]] = hlfir.designate %[[LOAD_ARG0]] (%{{.*}}) : (!fir.class<!fir.heap<!fir.array<?x!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>>>, i64) -> !fir.class<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>> |
| 284 |
! CHECK: fir.dispatch "tbp_pass"(%[[DESIGNATE]] : !fir.class<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>) (%[[DESIGNATE]] : !fir.class<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>) {pass_arg_pos = 0 : i32} |
| 285 |
|
| 286 |
! CHECK: %{{.*}} = fir.do_loop {{.*}} { |
| 287 |
! CHECK: %[[LOAD_ARG1:.*]] = fir.load %[[ARG1_DECL]]#0 : !fir.ref<!fir.box<!fir.heap<!fir.array<?x!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>>>> |
| 288 |
! CHECK: %[[DESIGNATE:.*]] = hlfir.designate %[[LOAD_ARG1]] (%{{.*}}) : (!fir.box<!fir.heap<!fir.array<?x!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>>>, i64) -> !fir.ref<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>> |
| 289 |
! CHECK: %[[EMBOX:.*]] = fir.embox %[[DESIGNATE]] : (!fir.ref<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>) -> !fir.box<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>> |
| 290 |
! CHECK: %[[CONV:.*]] = fir.convert %[[EMBOX]] : (!fir.box<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>) -> !fir.class<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>> |
| 291 |
! CHECK: fir.call @_QMcall_dispatchPtbp_pass(%[[CONV]]) {{.*}}: (!fir.class<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>) -> () |
| 292 |
|
| 293 |
subroutine check_dispatch_pointer_array(p, t) |
| 294 |
class(p1), pointer :: p(:) |
| 295 |
type(p1), pointer :: t(:) |
| 296 |
integer :: i |
| 297 |
do i = 1, 10 |
| 298 |
call p(i)%tbp_pass() |
| 299 |
end do |
| 300 |
|
| 301 |
do i = 1, 10 |
| 302 |
call t(i)%tbp_pass() |
| 303 |
end do |
| 304 |
end subroutine |
| 305 |
|
| 306 |
! CHECK-LABEL: func.func @_QMcall_dispatchPcheck_dispatch_pointer_array( |
| 307 |
! CHECK-SAME: %[[ARG0:.*]]: !fir.ref<!fir.class<!fir.ptr<!fir.array<?x!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>>>> {fir.bindc_name = "p"}, |
| 308 |
! CHECK-SAME: %[[ARG1:.*]]: !fir.ref<!fir.box<!fir.ptr<!fir.array<?x!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>>>> {fir.bindc_name = "t"}) { |
| 309 |
! CHECK: %[[ARG0_DECL:.*]]:2 = hlfir.declare %[[ARG0]] dummy_scope %{{[0-9]+}} {fortran_attrs = #fir.var_attrs<pointer>, uniq_name = "_QMcall_dispatchFcheck_dispatch_pointer_arrayEp"} : (!fir.ref<!fir.class<!fir.ptr<!fir.array<?x!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>>>>, !fir.dscope) -> (!fir.ref<!fir.class<!fir.ptr<!fir.array<?x!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>>>>, !fir.ref<!fir.class<!fir.ptr<!fir.array<?x!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>>>>) |
| 310 |
! CHECK: %[[ARG1_DECL:.*]]:2 = hlfir.declare %[[ARG1]] dummy_scope %{{[0-9]+}} {fortran_attrs = #fir.var_attrs<pointer>, uniq_name = "_QMcall_dispatchFcheck_dispatch_pointer_arrayEt"} : (!fir.ref<!fir.box<!fir.ptr<!fir.array<?x!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>>>>, !fir.dscope) -> (!fir.ref<!fir.box<!fir.ptr<!fir.array<?x!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>>>>, !fir.ref<!fir.box<!fir.ptr<!fir.array<?x!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>>>>) |
| 311 |
|
| 312 |
! CHECK: %{{.*}} = fir.do_loop {{.*}} { |
| 313 |
! CHECK: %[[LOAD_ARG0:.*]] = fir.load %[[ARG0_DECL]]#0 : !fir.ref<!fir.class<!fir.ptr<!fir.array<?x!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>>>> |
| 314 |
! CHECK: %[[DESIGNATE:.*]] = hlfir.designate %[[LOAD_ARG0]] (%{{.*}}) : (!fir.class<!fir.ptr<!fir.array<?x!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>>>, i64) -> !fir.class<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>> |
| 315 |
! CHECK: fir.dispatch "tbp_pass"(%[[DESIGNATE]] : !fir.class<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>) (%[[DESIGNATE]] : !fir.class<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>) {pass_arg_pos = 0 : i32} |
| 316 |
|
| 317 |
! CHECK: %{{.*}} = fir.do_loop {{.*}} { |
| 318 |
! CHECK: %[[LOAD_ARG1:.*]] = fir.load %[[ARG1_DECL]]#0 : !fir.ref<!fir.box<!fir.ptr<!fir.array<?x!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>>>> |
| 319 |
! CHECK: %[[DESIGNATE:.*]] = hlfir.designate %[[LOAD_ARG1]] (%{{.*}}) : (!fir.box<!fir.ptr<!fir.array<?x!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>>>, i64) -> !fir.ref<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>> |
| 320 |
! CHECK: %[[EMBOX:.*]] = fir.embox %[[DESIGNATE]] : (!fir.ref<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>) -> !fir.box<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>> |
| 321 |
! CHECK: %[[CONV:.*]] = fir.convert %[[EMBOX]] : (!fir.box<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>) -> !fir.class<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>> |
| 322 |
! CHECK: fir.call @_QMcall_dispatchPtbp_pass(%[[CONV]]) fastmath<contract> : (!fir.class<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>) -> () |
| 323 |
|
| 324 |
subroutine check_dispatch_dynamic_array_copy(p, o) |
| 325 |
class(p1) :: p(:) |
| 326 |
class(p1) :: o(:) |
| 327 |
|
| 328 |
integer :: i |
| 329 |
do i = 1, 9 |
| 330 |
call p(i)%pass_with_class_arg(o(i+1)) |
| 331 |
end do |
| 332 |
end subroutine |
| 333 |
|
| 334 |
! CHECK-LABEL: func.func @_QMcall_dispatchPcheck_dispatch_dynamic_array_copy( |
| 335 |
! CHECK-SAME: %[[ARG0:.*]]: !fir.class<!fir.array<?x!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>> {fir.bindc_name = "p"}, |
| 336 |
! CHECK-SAME: %[[ARG1:.*]]: !fir.class<!fir.array<?x!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>> {fir.bindc_name = "o"}) { |
| 337 |
! CHECK: %[[ARG1_DECL:.*]]:2 = hlfir.declare %[[ARG1]] dummy_scope %{{[0-9]+}} {uniq_name = "_QMcall_dispatchFcheck_dispatch_dynamic_array_copyEo"} : (!fir.class<!fir.array<?x!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>>, !fir.dscope) -> (!fir.class<!fir.array<?x!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>>, !fir.class<!fir.array<?x!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>>) |
| 338 |
! CHECK: %[[ARG0_DECL:.*]]:2 = hlfir.declare %[[ARG0]] dummy_scope %{{[0-9]+}} {uniq_name = "_QMcall_dispatchFcheck_dispatch_dynamic_array_copyEp"} : (!fir.class<!fir.array<?x!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>>, !fir.dscope) -> (!fir.class<!fir.array<?x!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>>, !fir.class<!fir.array<?x!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>>) |
| 339 |
|
| 340 |
! CHECK: %{{.*}} = fir.do_loop {{.*}} { |
| 341 |
! CHECK: %[[DESIGNATE0:.*]] = hlfir.designate %[[ARG0_DECL]]#0 (%{{.*}}) : (!fir.class<!fir.array<?x!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>>, i64) -> !fir.class<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>> |
| 342 |
! CHECK: %[[DESIGNATE1:.*]] = hlfir.designate %[[ARG1_DECL]]#0 (%{{.*}}) : (!fir.class<!fir.array<?x!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>>, i64) -> !fir.class<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>> |
| 343 |
! CHECK: fir.dispatch "pass_with_class_arg"(%[[DESIGNATE0]] : !fir.class<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>) (%[[DESIGNATE0]], %[[DESIGNATE1]] : !fir.class<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>, !fir.class<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>) {pass_arg_pos = 0 : i32} |
| 344 |
|
| 345 |
! ------------------------------------------------------------------------------ |
| 346 |
! Test that direct call is emitted when the type is known |
| 347 |
! ------------------------------------------------------------------------------ |
| 348 |
|
| 349 |
subroutine check_nodispatch(t) |
| 350 |
type(p1) :: t |
| 351 |
call t%tbp_nopass() |
| 352 |
call t%tbp_pass() |
| 353 |
call t%tbp_pass_arg0() |
| 354 |
call t%tbp_pass_arg1(1) |
| 355 |
end subroutine |
| 356 |
|
| 357 |
! CHECK-LABEL: func.func @_QMcall_dispatchPcheck_nodispatch |
| 358 |
! CHECK: fir.call @_QMcall_dispatchPtbp_nopass |
| 359 |
! CHECK: fir.call @_QMcall_dispatchPtbp_pass |
| 360 |
! CHECK: fir.call @_QMcall_dispatchPtbp_pass_arg0 |
| 361 |
! CHECK: fir.call @_QMcall_dispatchPtbp_pass_arg1 |
| 362 |
|
| 363 |
subroutine use_node_test(n) |
| 364 |
type(use_node) :: n |
| 365 |
end subroutine |
| 366 |
|
| 367 |
|
| 368 |
subroutine base_component() |
| 369 |
type(q1) :: q |
| 370 |
allocate(p1::q%p) |
| 371 |
|
| 372 |
call q%p%tbp_nopass() |
| 373 |
end subroutine |
| 374 |
|
| 375 |
! CHECK-LABEL: func.func @_QMcall_dispatchPbase_component() |
| 376 |
! CHECK: fir.dispatch "tbp_nopass"(%{{.*}} : !fir.class<!fir.heap<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>>) |
| 377 |
|
| 378 |
end module |