| 1 |
! RUN: bbc --use-desc-for-alloc=false -emit-fir -hlfir=false %s -o - | FileCheck %s |
| 2 |
|
| 3 |
! Tests various aspect of the lowering of polymorphic entities. |
| 4 |
|
| 5 |
module polymorphic_test |
| 6 |
type p1 |
| 7 |
integer :: a |
| 8 |
integer :: b |
| 9 |
contains |
| 10 |
procedure :: print |
| 11 |
procedure :: assign_p1_int |
| 12 |
procedure :: elemental_fct |
| 13 |
procedure :: elemental_sub |
| 14 |
procedure, pass(this) :: elemental_sub_pass |
| 15 |
procedure :: read_p1 |
| 16 |
procedure :: write_p1 |
| 17 |
generic :: read(formatted) => read_p1 |
| 18 |
generic :: write(formatted) => write_p1 |
| 19 |
generic :: assignment(=) => assign_p1_int |
| 20 |
procedure :: host_assoc |
| 21 |
procedure, pass(poly) :: lt |
| 22 |
generic :: operator(<) => lt |
| 23 |
end type |
| 24 |
|
| 25 |
type, extends(p1) :: p2 |
| 26 |
real :: c = 10.5 |
| 27 |
end type |
| 28 |
|
| 29 |
type r1 |
| 30 |
real, pointer :: rp(:) => null() |
| 31 |
end type |
| 32 |
|
| 33 |
type c1 |
| 34 |
character(2) :: tmp = 'c1' |
| 35 |
contains |
| 36 |
procedure :: get_tmp |
| 37 |
end type |
| 38 |
|
| 39 |
type p3 |
| 40 |
class(p3), pointer :: p(:) |
| 41 |
end type |
| 42 |
|
| 43 |
type outer |
| 44 |
type(p1) :: inner |
| 45 |
end type |
| 46 |
|
| 47 |
type non_extensible |
| 48 |
sequence |
| 49 |
integer :: d |
| 50 |
end type |
| 51 |
|
| 52 |
type :: p4 |
| 53 |
class(p1), allocatable :: a(:) |
| 54 |
end type |
| 55 |
|
| 56 |
type :: p5 |
| 57 |
class(*), allocatable :: up |
| 58 |
end type |
| 59 |
|
| 60 |
contains |
| 61 |
|
| 62 |
elemental subroutine assign_p1_int(lhs, rhs) |
| 63 |
class(p1), intent(inout) :: lhs |
| 64 |
integer, intent(in) :: rhs |
| 65 |
lhs%a = rhs |
| 66 |
lhs%b = rhs |
| 67 |
End Subroutine |
| 68 |
|
| 69 |
! CHECK-LABEL: func.func @_QMpolymorphic_testPhost_assoc( |
| 70 |
! CHECK-SAME: %[[THIS:.*]]: !fir.class<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>) { |
| 71 |
! CHECK: %[[TUPLE:.*]] = fir.alloca tuple<!fir.class<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>> |
| 72 |
! CHECK: %[[POS_IN_TUPLE:.*]] = arith.constant 0 : i32 |
| 73 |
! CHECK: %[[COORD_OF_CLASS:.*]] = fir.coordinate_of %[[TUPLE]], %[[POS_IN_TUPLE]] : (!fir.ref<tuple<!fir.class<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>>, i32) -> !fir.ref<!fir.class<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>> |
| 74 |
! CHECK: fir.store %[[THIS]] to %[[COORD_OF_CLASS]] : !fir.ref<!fir.class<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>> |
| 75 |
! CHECK: fir.call @_QMpolymorphic_testFhost_assocPinternal(%[[TUPLE]]) {{.*}} : (!fir.ref<tuple<!fir.class<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>>) -> () |
| 76 |
|
| 77 |
elemental integer function elemental_fct(this) |
| 78 |
class(p1), intent(in) :: this |
| 79 |
elemental_fct = this%a |
| 80 |
end function |
| 81 |
|
| 82 |
elemental subroutine elemental_sub(this) |
| 83 |
class(p1), intent(inout) :: this |
| 84 |
this%a = this%a * this%b |
| 85 |
end subroutine |
| 86 |
|
| 87 |
elemental subroutine elemental_sub_pass(c, this) |
| 88 |
integer, intent(in) :: c |
| 89 |
class(p1), intent(inout) :: this |
| 90 |
this%a = this%a * this%b + c |
| 91 |
end subroutine |
| 92 |
|
| 93 |
logical elemental function lt(i, poly) |
| 94 |
integer, intent(in) :: i |
| 95 |
class(p1), intent(in) :: poly |
| 96 |
lt = i < poly%a |
| 97 |
End Function |
| 98 |
|
| 99 |
! Test correct access to polymorphic entity component. |
| 100 |
subroutine component_access(p) |
| 101 |
class(p1) :: p |
| 102 |
print*, p%a |
| 103 |
end subroutine |
| 104 |
|
| 105 |
! CHECK-LABEL: func.func @_QMpolymorphic_testPcomponent_access( |
| 106 |
! CHECK-SAME: %[[P:.*]]: !fir.class<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>> {fir.bindc_name = "p"}) { |
| 107 |
! CHECK: %[[FIELD:.*]] = fir.field_index a, !fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}> |
| 108 |
! CHECK: %[[COORD:.*]] = fir.coordinate_of %[[P]], %[[FIELD]] : (!fir.class<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>, !fir.field) -> !fir.ref<i32> |
| 109 |
! CHECK: %[[LOAD:.*]] = fir.load %[[COORD]] : !fir.ref<i32> |
| 110 |
! CHECK: %{{.*}} = fir.call @_FortranAioOutputInteger32(%{{.*}}, %[[LOAD]]) {{.*}}: (!fir.ref<i8>, i32) -> i1 |
| 111 |
|
| 112 |
subroutine print(this) |
| 113 |
class(p1) :: this |
| 114 |
end subroutine |
| 115 |
|
| 116 |
! Test embox of fir.type to fir.class to be passed-object. |
| 117 |
subroutine check() |
| 118 |
type(p1) :: t1 |
| 119 |
type(p2) :: t2 |
| 120 |
call t1%print() |
| 121 |
call t2%print() |
| 122 |
end subroutine |
| 123 |
|
| 124 |
! CHECK-LABEL: func.func @_QMpolymorphic_testPcheck() |
| 125 |
! CHECK: %[[DT1:.*]] = fir.alloca !fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}> {bindc_name = "t1", uniq_name = "_QMpolymorphic_testFcheckEt1"} |
| 126 |
! CHECK: %[[DT2:.*]] = fir.alloca !fir.type<_QMpolymorphic_testTp2{a:i32,b:i32,c:f32}> {bindc_name = "t2", uniq_name = "_QMpolymorphic_testFcheckEt2"} |
| 127 |
! CHECK: %[[CLASS1:.*]] = fir.embox %[[DT1]] : (!fir.ref<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>) -> !fir.class<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>> |
| 128 |
! CHECK: fir.call @_QMpolymorphic_testPprint(%[[CLASS1]]) {{.*}}: (!fir.class<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>) -> () |
| 129 |
! CHECK: %[[BOX2:.*]] = fir.embox %[[DT2]] : (!fir.ref<!fir.type<_QMpolymorphic_testTp2{a:i32,b:i32,c:f32}>>) -> !fir.class<!fir.type<_QMpolymorphic_testTp2{a:i32,b:i32,c:f32}>> |
| 130 |
! CHECK: %[[CLASS2:.*]] = fir.convert %[[BOX2]] : (!fir.class<!fir.type<_QMpolymorphic_testTp2{a:i32,b:i32,c:f32}>>) -> !fir.class<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>> |
| 131 |
! CHECK: fir.call @_QMpolymorphic_testPprint(%[[CLASS2]]) {{.*}}: (!fir.class<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>) -> () |
| 132 |
|
| 133 |
subroutine test_allocate_unlimited_polymorphic_non_derived() |
| 134 |
class(*), pointer :: u |
| 135 |
allocate(integer::u) |
| 136 |
end subroutine |
| 137 |
|
| 138 |
! CHECK-LABEL: test_allocate_unlimited_polymorphic_non_derived |
| 139 |
! CHECK-NOT: _FortranAPointerNullifyDerived |
| 140 |
! CHECK: fir.call @_FortranAPointerAllocate |
| 141 |
|
| 142 |
function test_fct_ret_class() |
| 143 |
class(p1), pointer :: test_fct_ret_class |
| 144 |
end function |
| 145 |
|
| 146 |
subroutine call_fct() |
| 147 |
class(p1), pointer :: p |
| 148 |
p => test_fct_ret_class() |
| 149 |
end subroutine |
| 150 |
|
| 151 |
! CHECK-LABEL: func.func @_QMpolymorphic_testPtest_fct_ret_class() -> !fir.class<!fir.ptr<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>> |
| 152 |
! CHECK: return %{{.*}} : !fir.class<!fir.ptr<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>> |
| 153 |
|
| 154 |
! CHECK-lABEL: func.func @_QMpolymorphic_testPcall_fct() |
| 155 |
! CHECK: %[[RESULT:.*]] = fir.alloca !fir.class<!fir.ptr<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>> {bindc_name = ".result"} |
| 156 |
! CHECK: %[[CALL_RES:.*]] = fir.call @_QMpolymorphic_testPtest_fct_ret_class() {{.*}}: () -> !fir.class<!fir.ptr<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>> |
| 157 |
! CHECK: fir.save_result %[[CALL_RES]] to %[[RESULT]] : !fir.class<!fir.ptr<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>, !fir.ref<!fir.class<!fir.ptr<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>> |
| 158 |
|
| 159 |
subroutine implicit_loop_with_polymorphic() |
| 160 |
class(p1), allocatable :: p(:) |
| 161 |
allocate(p(3)) |
| 162 |
p%a = [ 1, 2, 3 ] |
| 163 |
end subroutine |
| 164 |
|
| 165 |
! CHECK-LABEL: func.func @_QMpolymorphic_testPimplicit_loop_with_polymorphic() { |
| 166 |
! CHECK: %{{.*}} = fir.array_load %{{.*}}(%{{.*}}) [%{{.*}}] : (!fir.class<!fir.heap<!fir.array<?x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>>, !fir.shift<1>, !fir.slice<1>) -> !fir.array<?xi32> |
| 167 |
! CHECK: %{{.*}} = fir.do_loop %{{.*}} = %{{.*}} to %{{.*}} step %{{.*}} unordered iter_args(%{{.*}} = %{{.*}}) -> (!fir.array<?xi32>) { |
| 168 |
! CHECK: %{{.*}} = fir.array_fetch %{{.*}}, %{{.*}} : (!fir.array<3xi32>, index) -> i32 |
| 169 |
! CHECK: %{{.*}} = fir.array_update %{{.*}}, %{{.*}}, %{{.*}} : (!fir.array<?xi32>, i32, index) -> !fir.array<?xi32> |
| 170 |
! CHECK: } |
| 171 |
! CHECK: fir.array_merge_store %{{.*}}, %{{.*}} to %{{.*}}[%{{.*}}] : !fir.array<?xi32>, !fir.array<?xi32>, !fir.class<!fir.heap<!fir.array<?x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>>, !fir.slice<1> |
| 172 |
|
| 173 |
subroutine polymorphic_to_nonpolymorphic(p) |
| 174 |
class(p1), pointer :: p(:) |
| 175 |
type(p1), allocatable, target :: t(:) |
| 176 |
t = p |
| 177 |
end subroutine |
| 178 |
|
| 179 |
! CHECK-LABEL: func.func @_QMpolymorphic_testPpolymorphic_to_nonpolymorphic |
| 180 |
! Just checking that FIR is generated without error. |
| 181 |
|
| 182 |
! Test that lowering does not crash for function return with unlimited |
| 183 |
! polymoprhic value. |
| 184 |
|
| 185 |
function up_ret() |
| 186 |
class(*), pointer :: up_ret(:) |
| 187 |
end function |
| 188 |
|
| 189 |
! CHECK-LABEL: func.func @_QMpolymorphic_testPup_ret() -> !fir.class<!fir.ptr<!fir.array<?xnone>>> { |
| 190 |
|
| 191 |
subroutine call_up_ret() |
| 192 |
class(*), pointer :: p(:) |
| 193 |
p => up_ret() |
| 194 |
end subroutine |
| 195 |
|
| 196 |
! CHECK-LABEL: func.func @_QMpolymorphic_testPcall_up_ret() { |
| 197 |
! CHECK: %{{.*}} = fir.call @_QMpolymorphic_testPup_ret() {{.*}} : () -> !fir.class<!fir.ptr<!fir.array<?xnone>>> |
| 198 |
|
| 199 |
subroutine associate_up_pointer(r) |
| 200 |
class(r1) :: r |
| 201 |
class(*), pointer :: p(:) |
| 202 |
p => r%rp |
| 203 |
end subroutine |
| 204 |
|
| 205 |
! CHECK-LABEL: func.func @_QMpolymorphic_testPassociate_up_pointer( |
| 206 |
! CHECK-SAME: %[[ARG0:.*]]: !fir.class<!fir.type<_QMpolymorphic_testTr1{rp:!fir.box<!fir.ptr<!fir.array<?xf32>>>}>> {fir.bindc_name = "r"}) { |
| 207 |
! CHECK: %[[P:.*]] = fir.alloca !fir.class<!fir.ptr<!fir.array<?xnone>>> {bindc_name = "p", uniq_name = "_QMpolymorphic_testFassociate_up_pointerEp"} |
| 208 |
! CHECK: %[[FIELD_RP:.*]] = fir.field_index rp, !fir.type<_QMpolymorphic_testTr1{rp:!fir.box<!fir.ptr<!fir.array<?xf32>>>}> |
| 209 |
! CHECK: %[[COORD_RP:.*]] = fir.coordinate_of %[[ARG0]], %[[FIELD_RP]] : (!fir.class<!fir.type<_QMpolymorphic_testTr1{rp:!fir.box<!fir.ptr<!fir.array<?xf32>>>}>>, !fir.field) -> !fir.ref<!fir.box<!fir.ptr<!fir.array<?xf32>>>> |
| 210 |
! CHECK: %[[LOAD_RP:.*]] = fir.load %[[COORD_RP]] : !fir.ref<!fir.box<!fir.ptr<!fir.array<?xf32>>>> |
| 211 |
! CHECK: %[[REBOX_RP:.*]] = fir.rebox %[[LOAD_RP]](%{{.*}}) : (!fir.box<!fir.ptr<!fir.array<?xf32>>>, !fir.shift<1>) -> !fir.box<!fir.array<?xf32>> |
| 212 |
! CHECK: %[[CONV_P:.*]] = fir.convert %[[P]] : (!fir.ref<!fir.class<!fir.ptr<!fir.array<?xnone>>>>) -> !fir.ref<!fir.box<none>> |
| 213 |
! CHECK: %[[RP_BOX_NONE:.*]] = fir.convert %[[REBOX_RP]] : (!fir.box<!fir.array<?xf32>>) -> !fir.box<none> |
| 214 |
! CHECK: %{{.*}} = fir.call @_FortranAPointerAssociate(%[[CONV_P]], %[[RP_BOX_NONE]]) {{.*}} : (!fir.ref<!fir.box<none>>, !fir.box<none>) -> none |
| 215 |
! CHECK: return |
| 216 |
|
| 217 |
! Test that the fir.dispatch operation is created with the correct pass object |
| 218 |
! and the pass_arg_pos attribute is incremented correctly when character |
| 219 |
! function result is added as argument. |
| 220 |
|
| 221 |
function get_tmp(this) |
| 222 |
class(c1) :: this |
| 223 |
character(2) :: get_tmp |
| 224 |
get_tmp = this%tmp |
| 225 |
end function |
| 226 |
|
| 227 |
subroutine call_get_tmp(c) |
| 228 |
class(c1) :: c |
| 229 |
print*, c%get_tmp() |
| 230 |
end subroutine |
| 231 |
|
| 232 |
! CHECK-LABEL: func.func @_QMpolymorphic_testPcall_get_tmp( |
| 233 |
! CHECK-SAME: %[[ARG0:.*]]: !fir.class<!fir.type<_QMpolymorphic_testTc1{tmp:!fir.char<1,2>}>> {fir.bindc_name = "c"}) { |
| 234 |
! CHECK: %{{.*}} = fir.dispatch "get_tmp"(%[[ARG0]] : !fir.class<!fir.type<_QMpolymorphic_testTc1{tmp:!fir.char<1,2>}>>) (%{{.*}}, %{{.*}}, %[[ARG0]] : !fir.ref<!fir.char<1,2>>, index, !fir.class<!fir.type<_QMpolymorphic_testTc1{tmp:!fir.char<1,2>}>>) -> !fir.boxchar<1> {pass_arg_pos = 2 : i32} |
| 235 |
|
| 236 |
subroutine sub_with_type_array(a) |
| 237 |
type(p1) :: a(:) |
| 238 |
end subroutine |
| 239 |
|
| 240 |
! CHECK-LABEL: func.func @_QMpolymorphic_testPsub_with_type_array(%{{.*}}: !fir.box<!fir.array<?x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>> {fir.bindc_name = "a"}) |
| 241 |
|
| 242 |
subroutine call_sub_with_type_array(p) |
| 243 |
class(p1), pointer :: p(:) |
| 244 |
call sub_with_type_array(p) |
| 245 |
end subroutine |
| 246 |
|
| 247 |
! CHECK-LABEL: func.func @_QMpolymorphic_testPcall_sub_with_type_array( |
| 248 |
! CHECK-SAME: %[[ARG0:.*]]: !fir.ref<!fir.class<!fir.ptr<!fir.array<?x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>>> {fir.bindc_name = "p"}) { |
| 249 |
! CHECK: %[[CLASS:.*]] = fir.load %[[ARG0]] : !fir.ref<!fir.class<!fir.ptr<!fir.array<?x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>>> |
| 250 |
! CHECK: %[[REBOX:.*]] = fir.rebox %[[CLASS]] : (!fir.class<!fir.ptr<!fir.array<?x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>>) -> !fir.box<!fir.array<?x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>> |
| 251 |
! CHECK: fir.call @_QMpolymorphic_testPsub_with_type_array(%[[REBOX]]) {{.*}} : (!fir.box<!fir.array<?x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>) -> () |
| 252 |
|
| 253 |
subroutine derived_type_assignment_with_class() |
| 254 |
type(p3) :: a |
| 255 |
type(p3), target :: b(10) |
| 256 |
a = p3(b) |
| 257 |
end subroutine |
| 258 |
|
| 259 |
subroutine takes_p1(p) |
| 260 |
class(p1), intent(in) :: p |
| 261 |
end subroutine |
| 262 |
|
| 263 |
! TODO: implement polymorphic temporary in lowering |
| 264 |
! subroutine no_reassoc_poly_value(a, i) |
| 265 |
! class(p1), intent(in) :: a(:) |
| 266 |
! integer :: i |
| 267 |
! call takes_p1((a(i))) |
| 268 |
! end subroutine |
| 269 |
|
| 270 |
! Test pointer assignment with non polymorphic lhs and polymorphic rhs |
| 271 |
|
| 272 |
subroutine pointer_assign_parent(p) |
| 273 |
type(p2), target :: p |
| 274 |
type(p1), pointer :: tp |
| 275 |
tp => p%p1 |
| 276 |
end subroutine |
| 277 |
|
| 278 |
! First test is here to have a reference with non polymorphic on both sides. |
| 279 |
! CHECK-LABEL: func.func @_QMpolymorphic_testPpointer_assign_parent( |
| 280 |
! CHECK-SAME: %[[ARG0:.*]]: !fir.ref<!fir.type<_QMpolymorphic_testTp2{a:i32,b:i32,c:f32}>> {fir.bindc_name = "p", fir.target}) { |
| 281 |
! CHECK: %[[TP:.*]] = fir.alloca !fir.box<!fir.ptr<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>> {bindc_name = "tp", uniq_name = "_QMpolymorphic_testFpointer_assign_parentEtp"} |
| 282 |
! CHECK: %[[PTR:.*]] = fir.alloca !fir.ptr<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>> {uniq_name = "_QMpolymorphic_testFpointer_assign_parentEtp.addr"} |
| 283 |
! CHECK: %[[ZERO:.*]] = fir.zero_bits !fir.ptr<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>> |
| 284 |
! CHECK: fir.store %[[ZERO]] to %[[PTR]] : !fir.ref<!fir.ptr<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>> |
| 285 |
! CHECK: %[[CONVERT:.*]] = fir.convert %[[ARG0]] : (!fir.ref<!fir.type<_QMpolymorphic_testTp2{a:i32,b:i32,c:f32}>>) -> !fir.ptr<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>> |
| 286 |
! CHECK: fir.store %[[CONVERT]] to %[[PTR]] : !fir.ref<!fir.ptr<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>> |
| 287 |
|
| 288 |
subroutine pointer_assign_non_poly(p) |
| 289 |
class(p1), target :: p |
| 290 |
type(p1), pointer :: tp |
| 291 |
tp => p |
| 292 |
end subroutine |
| 293 |
|
| 294 |
! CHECK-LABEL: func.func @_QMpolymorphic_testPpointer_assign_non_poly( |
| 295 |
! CHECK-SAME: %arg0: !fir.class<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>> {fir.bindc_name = "p", fir.target}) { |
| 296 |
! CHECK: %[[TP:.*]] = fir.alloca !fir.box<!fir.ptr<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>> {bindc_name = "tp", uniq_name = "_QMpolymorphic_testFpointer_assign_non_polyEtp"} |
| 297 |
! CHECK: %[[PTR:.*]] = fir.alloca !fir.ptr<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>> {uniq_name = "_QMpolymorphic_testFpointer_assign_non_polyEtp.addr"} |
| 298 |
! CHECK: %[[ZERO:.*]] = fir.zero_bits !fir.ptr<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>> |
| 299 |
! CHECK: fir.store %[[ZERO]] to %[[PTR]] : !fir.ref<!fir.ptr<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>> |
| 300 |
! CHECK: %[[BOX_ADDR:.*]] = fir.box_addr %[[ARG0]] : (!fir.class<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>) -> !fir.ref<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>> |
| 301 |
! CHECK: %[[CONVERT:.*]] = fir.convert %{{[0-9]+}} : (!fir.ref<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>) -> !fir.ptr<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>> |
| 302 |
! CHECK: fir.store %[[CONVERT]] to %[[PTR]] : !fir.ref<!fir.ptr<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>> |
| 303 |
|
| 304 |
subroutine nullify_pointer_array(a) |
| 305 |
type(p3) :: a |
| 306 |
nullify(a%p) |
| 307 |
end subroutine |
| 308 |
|
| 309 |
! CHECK-LABEL: func.func @_QMpolymorphic_testPnullify_pointer_array( |
| 310 |
! CHECK-SAME: %[[ARG0:.*]]: !fir.ref<!fir.type<_QMpolymorphic_testTp3{p:!fir.class<!fir.ptr<!fir.array<?x!fir.type<_QMpolymorphic_testTp3>>>>}>> {fir.bindc_name = "a"}) { |
| 311 |
! CHECK: %[[FIELD_P:.*]] = fir.field_index p, !fir.type<_QMpolymorphic_testTp3{p:!fir.class<!fir.ptr<!fir.array<?x!fir.type<_QMpolymorphic_testTp3>>>>}> |
| 312 |
! CHECK: %[[COORD_P:.*]] = fir.coordinate_of %[[ARG0]], %[[FIELD_P]] : (!fir.ref<!fir.type<_QMpolymorphic_testTp3{p:!fir.class<!fir.ptr<!fir.array<?x!fir.type<_QMpolymorphic_testTp3>>>>}>>, !fir.field) -> !fir.ref<!fir.class<!fir.ptr<!fir.array<?x!fir.type<_QMpolymorphic_testTp3{p:!fir.class<!fir.ptr<!fir.array<?x!fir.type<_QMpolymorphic_testTp3>>>>}>>>>> |
| 313 |
! CHECK: %[[TYPE_DESC:.*]] = fir.type_desc !fir.type<_QMpolymorphic_testTp3{p:!fir.class<!fir.ptr<!fir.array<?x!fir.type<_QMpolymorphic_testTp3>>>>}> |
| 314 |
! CHECK: %[[CONV_P:.*]] = fir.convert %[[COORD_P]] : (!fir.ref<!fir.class<!fir.ptr<!fir.array<?x!fir.type<_QMpolymorphic_testTp3{p:!fir.class<!fir.ptr<!fir.array<?x!fir.type<_QMpolymorphic_testTp3>>>>}>>>>>) -> !fir.ref<!fir.box<none>> |
| 315 |
! CHECK: %[[CONV_TDESC:.*]] = fir.convert %[[TYPE_DESC]] : (!fir.tdesc<!fir.type<_QMpolymorphic_testTp3{p:!fir.class<!fir.ptr<!fir.array<?x!fir.type<_QMpolymorphic_testTp3>>>>}>>) -> !fir.ref<none> |
| 316 |
! CHECK: %[[C1:.*]] = arith.constant 1 : i32 |
| 317 |
! CHECK: %[[C0:.*]] = arith.constant 0 : i32 |
| 318 |
! CHECK: %{{.*}} = fir.call @_FortranAPointerNullifyDerived(%[[CONV_P]], %[[CONV_TDESC]], %[[C1]], %[[C0]]) {{.*}} : (!fir.ref<!fir.box<none>>, !fir.ref<none>, i32, i32) -> none |
| 319 |
|
| 320 |
subroutine up_input(a) |
| 321 |
class(*), intent(in) :: a |
| 322 |
end subroutine |
| 323 |
|
| 324 |
subroutine pass_trivial_to_up() |
| 325 |
call up_input('hello') |
| 326 |
call up_input(1) |
| 327 |
call up_input(2.5) |
| 328 |
call up_input(.true.) |
| 329 |
call up_input((-1.0,3)) |
| 330 |
end subroutine |
| 331 |
|
| 332 |
! CHECK-LABEL: func.func @_QMpolymorphic_testPpass_trivial_to_up() { |
| 333 |
! CHECK: %[[CHAR:.*]] = fir.address_of(@_QQclX{{.*}}) : !fir.ref<!fir.char<1,5>> |
| 334 |
! CHECK: %[[BOX_CHAR:.*]] = fir.embox %[[CHAR]] : (!fir.ref<!fir.char<1,5>>) -> !fir.class<none> |
| 335 |
! CHECK: fir.call @_QMpolymorphic_testPup_input(%[[BOX_CHAR]]) {{.*}} : (!fir.class<none>) -> () |
| 336 |
|
| 337 |
! CHECK: %[[BOX_INT:.*]] = fir.embox %{{.*}} : (!fir.ref<i32>) -> !fir.class<none> |
| 338 |
! CHECK: fir.call @_QMpolymorphic_testPup_input(%[[BOX_INT]]) {{.*}} : (!fir.class<none>) -> () |
| 339 |
|
| 340 |
! CHECK: %[[BOX_REAL:.*]] = fir.embox %{{.*}} : (!fir.ref<f32>) -> !fir.class<none> |
| 341 |
! CHECK: fir.call @_QMpolymorphic_testPup_input(%[[BOX_REAL]]) {{.*}} : (!fir.class<none>) -> () |
| 342 |
|
| 343 |
! CHECK: %[[BOX_LOG:.*]] = fir.embox %{{.*}} : (!fir.ref<!fir.logical<4>>) -> !fir.class<none> |
| 344 |
! CHECK: fir.call @_QMpolymorphic_testPup_input(%[[BOX_LOG]]) {{.*}} : (!fir.class<none>) -> () |
| 345 |
|
| 346 |
! CHECK: %[[BOX_COMPLEX:.*]] = fir.embox %{{.*}} : (!fir.ref<!fir.complex<4>>) -> !fir.class<none> |
| 347 |
! CHECK: fir.call @_QMpolymorphic_testPup_input(%[[BOX_COMPLEX]]) {{.*}} : (!fir.class<none>) -> () |
| 348 |
|
| 349 |
subroutine up_arr_input(a) |
| 350 |
class(*), intent(in) :: a(2) |
| 351 |
end subroutine |
| 352 |
|
| 353 |
subroutine pass_trivial_arr_to_up() |
| 354 |
character :: c(2) |
| 355 |
integer :: i(2) |
| 356 |
real :: r(2) |
| 357 |
logical :: l(2) |
| 358 |
complex :: cx(2) |
| 359 |
|
| 360 |
call up_arr_input(c) |
| 361 |
call up_arr_input(i) |
| 362 |
call up_arr_input(r) |
| 363 |
call up_arr_input(l) |
| 364 |
call up_arr_input(cx) |
| 365 |
end subroutine |
| 366 |
|
| 367 |
! CHECK-LABEL: func.func @_QMpolymorphic_testPpass_trivial_arr_to_up() { |
| 368 |
! CHECK: %[[BOX_CHAR:.*]] = fir.embox %{{.*}}(%{{.*}}) : (!fir.ref<!fir.array<2x!fir.char<1>>>, !fir.shape<1>) -> !fir.class<!fir.array<2xnone>> |
| 369 |
! CHECK: fir.call @_QMpolymorphic_testPup_arr_input(%[[BOX_CHAR]]) {{.*}} : (!fir.class<!fir.array<2xnone>>) -> () |
| 370 |
|
| 371 |
! CHECK: %[[BOX_INT:.*]] = fir.embox %{{.*}}(%{{.*}}) : (!fir.ref<!fir.array<2xi32>>, !fir.shape<1>) -> !fir.class<!fir.array<2xnone>> |
| 372 |
! CHECK: fir.call @_QMpolymorphic_testPup_arr_input(%[[BOX_INT]]) {{.*}} : (!fir.class<!fir.array<2xnone>>) -> () |
| 373 |
|
| 374 |
! CHECK: %[[BOX_REAL:.*]] = fir.embox %{{.*}}(%{{.*}}) : (!fir.ref<!fir.array<2xf32>>, !fir.shape<1>) -> !fir.class<!fir.array<2xnone>> |
| 375 |
! CHECK: fir.call @_QMpolymorphic_testPup_arr_input(%[[BOX_REAL]]) {{.*}} : (!fir.class<!fir.array<2xnone>>) -> () |
| 376 |
|
| 377 |
! CHECK: %[[BOX_LOG:.*]] = fir.embox %{{.*}}(%{{.*}}) : (!fir.ref<!fir.array<2x!fir.logical<4>>>, !fir.shape<1>) -> !fir.class<!fir.array<2xnone>> |
| 378 |
! CHECK: fir.call @_QMpolymorphic_testPup_arr_input(%[[BOX_LOG]]) {{.*}} : (!fir.class<!fir.array<2xnone>>) -> () |
| 379 |
|
| 380 |
! CHECK: %[[BOX_COMPLEX:.*]] = fir.embox %{{.*}}(%{{.*}}) : (!fir.ref<!fir.array<2x!fir.complex<4>>>, !fir.shape<1>) -> !fir.class<!fir.array<2xnone>> |
| 381 |
! CHECK: fir.call @_QMpolymorphic_testPup_arr_input(%[[BOX_COMPLEX]]) {{.*}} : (!fir.class<!fir.array<2xnone>>) -> () |
| 382 |
|
| 383 |
subroutine assign_polymorphic_allocatable() |
| 384 |
type(p1), target :: t(10,20) |
| 385 |
class(p1), allocatable :: c(:,:) |
| 386 |
c = t |
| 387 |
end subroutine |
| 388 |
|
| 389 |
! CHECK-LABEL: func.func @_QMpolymorphic_testPassign_polymorphic_allocatable() { |
| 390 |
! CHECK: %[[C:.*]] = fir.alloca !fir.class<!fir.heap<!fir.array<?x?x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>> {bindc_name = "c", uniq_name = "_QMpolymorphic_testFassign_polymorphic_allocatableEc"} |
| 391 |
! CHECK: %[[ZERO:.*]] = fir.zero_bits !fir.heap<!fir.array<?x?x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>> |
| 392 |
! CHECK: %[[C0:.*]] = arith.constant 0 : index |
| 393 |
! CHECK: %[[SHAPE_C:.*]] = fir.shape %[[C0]], %[[C0]] : (index, index) -> !fir.shape<2> |
| 394 |
! CHECK: %[[EMBOX:.*]] = fir.embox %[[ZERO]](%[[SHAPE_C]]) : (!fir.heap<!fir.array<?x?x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>, !fir.shape<2>) -> !fir.class<!fir.heap<!fir.array<?x?x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>> |
| 395 |
! CHECK: fir.store %[[EMBOX]] to %[[C]] : !fir.ref<!fir.class<!fir.heap<!fir.array<?x?x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>>> |
| 396 |
! CHECK: %[[C10:.*]] = arith.constant 10 : index |
| 397 |
! CHECK: %[[C20:.*]] = arith.constant 20 : index |
| 398 |
! CHECK: %[[T:.*]] = fir.alloca !fir.array<10x20x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>> {bindc_name = "t", fir.target, uniq_name = "_QMpolymorphic_testFassign_polymorphic_allocatableEt"} |
| 399 |
! CHECK: %[[SHAPE:.*]] = fir.shape %[[C10]], %[[C20]] : (index, index) -> !fir.shape<2> |
| 400 |
! CHECK: %[[BOXED_T:.*]] = fir.embox %[[T]](%[[SHAPE]]) : (!fir.ref<!fir.array<10x20x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>, !fir.shape<2>) -> !fir.box<!fir.array<10x20x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>> |
| 401 |
! CHECK: %[[CONV_C:.*]] = fir.convert %[[C]] : (!fir.ref<!fir.class<!fir.heap<!fir.array<?x?x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>>>) -> !fir.ref<!fir.box<none>> |
| 402 |
! CHECK: %[[CONV_BOXED_T:.*]] = fir.convert %[[BOXED_T]] : (!fir.box<!fir.array<10x20x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>) -> !fir.box<none> |
| 403 |
! CHECK: %{{.*}} = fir.call @_FortranAAssignPolymorphic(%[[CONV_C]], %[[CONV_BOXED_T]], %{{.*}}, %{{.*}}) fastmath<contract> : (!fir.ref<!fir.box<none>>, !fir.box<none>, !fir.ref<i8>, i32) -> none |
| 404 |
! CHECK: return |
| 405 |
|
| 406 |
subroutine pointer_assign_remap() |
| 407 |
class(p1), pointer :: a(:) |
| 408 |
class(p1), pointer :: p(:,:) |
| 409 |
class(p1), pointer :: q(:) |
| 410 |
allocate(a(100)) |
| 411 |
p(1:10,1:10) => a |
| 412 |
q(0:99) => a |
| 413 |
end subroutine |
| 414 |
|
| 415 |
! CHECK-LABEL: func.func @_QMpolymorphic_testPpointer_assign_remap() { |
| 416 |
! CHECK: %[[A:.*]] = fir.alloca !fir.class<!fir.ptr<!fir.array<?x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>> {bindc_name = "a", uniq_name = "_QMpolymorphic_testFpointer_assign_remapEa"} |
| 417 |
! CHECK: %[[P:.*]] = fir.alloca !fir.class<!fir.ptr<!fir.array<?x?x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>> {bindc_name = "p", uniq_name = "_QMpolymorphic_testFpointer_assign_remapEp"} |
| 418 |
! CHECK: %[[Q:.*]] = fir.alloca !fir.class<!fir.ptr<!fir.array<?x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>> {bindc_name = "q", uniq_name = "_QMpolymorphic_testFpointer_assign_remapEq"} |
| 419 |
! CHECK: %[[C1_0:.*]] = arith.constant 1 : i64 |
| 420 |
! CHECK: %[[C10_0:.*]] = arith.constant 10 : i64 |
| 421 |
! CHECK: %[[C1_1:.*]] = arith.constant 1 : i64 |
| 422 |
! CHECK: %[[C10_1:.*]] = arith.constant 10 : i64 |
| 423 |
! CHECK: %[[LOAD_A:.*]] = fir.load %[[A]] : !fir.ref<!fir.class<!fir.ptr<!fir.array<?x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>>> |
| 424 |
! CHECK: %[[REBOX_A:.*]] = fir.rebox %[[LOAD_A]](%{{.*}}) : (!fir.class<!fir.ptr<!fir.array<?x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>>, !fir.shift<1>) -> !fir.class<!fir.array<?x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>> |
| 425 |
! CHECK: %[[BOUND_ARRAY:.*]] = fir.alloca !fir.array<2x2xi64> |
| 426 |
! CHECK: %[[ARRAY:.*]] = fir.undefined !fir.array<2x2xi64> |
| 427 |
! CHECK: %[[ARRAY0:.*]] = fir.insert_value %[[ARRAY]], %[[C1_0]], [0 : index, 0 : index] : (!fir.array<2x2xi64>, i64) -> !fir.array<2x2xi64> |
| 428 |
! CHECK: %[[ARRAY1:.*]] = fir.insert_value %[[ARRAY0]], %[[C10_0]], [1 : index, 0 : index] : (!fir.array<2x2xi64>, i64) -> !fir.array<2x2xi64> |
| 429 |
! CHECK: %[[ARRAY2:.*]] = fir.insert_value %[[ARRAY1]], %[[C1_1]], [0 : index, 1 : index] : (!fir.array<2x2xi64>, i64) -> !fir.array<2x2xi64> |
| 430 |
! CHECK: %[[ARRAY3:.*]] = fir.insert_value %[[ARRAY2]], %[[C10_1]], [1 : index, 1 : index] : (!fir.array<2x2xi64>, i64) -> !fir.array<2x2xi64> |
| 431 |
! CHECK: fir.store %[[ARRAY3]] to %[[BOUND_ARRAY]] : !fir.ref<!fir.array<2x2xi64>> |
| 432 |
! CHECK: %[[C2_0:.*]] = arith.constant 2 : index |
| 433 |
! CHECK: %[[C2_1:.*]] = arith.constant 2 : index |
| 434 |
! CHECK: %[[BOUND_ARRAY_SHAPE:.*]] = fir.shape %[[C2_1]], %[[C2_0]] : (index, index) -> !fir.shape<2> |
| 435 |
! CHECK: %[[BOXED_BOUND_ARRAY:.*]] = fir.embox %[[BOUND_ARRAY]](%[[BOUND_ARRAY_SHAPE]]) : (!fir.ref<!fir.array<2x2xi64>>, !fir.shape<2>) -> !fir.box<!fir.array<2x2xi64>> |
| 436 |
! CHECK: %[[ARG0:.*]] = fir.convert %[[P]] : (!fir.ref<!fir.class<!fir.ptr<!fir.array<?x?x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>>>) -> !fir.ref<!fir.box<none>> |
| 437 |
! CHECK: %[[ARG1:.*]] = fir.convert %[[REBOX_A]] : (!fir.class<!fir.array<?x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>) -> !fir.box<none> |
| 438 |
! CHECK: %[[ARG2:.*]] = fir.convert %[[BOXED_BOUND_ARRAY]] : (!fir.box<!fir.array<2x2xi64>>) -> !fir.box<none> |
| 439 |
! CHECK: %{{.*}} = fir.call @_FortranAPointerAssociateRemapping(%[[ARG0]], %[[ARG1]], %[[ARG2]], %{{.*}}, %{{.*}}) {{.*}} : (!fir.ref<!fir.box<none>>, !fir.box<none>, !fir.box<none>, !fir.ref<i8>, i32) -> none |
| 440 |
|
| 441 |
! CHECK: %[[C0:.*]] = arith.constant 0 : i64 |
| 442 |
! CHECK: %[[C99:.*]] = arith.constant 99 : i64 |
| 443 |
! CHECK: %[[LOAD_A:.*]] = fir.load %[[A]] : !fir.ref<!fir.class<!fir.ptr<!fir.array<?x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>>> |
| 444 |
! CHECK: %[[REBOX_A:.*]] = fir.rebox %[[LOAD_A]](%{{.*}}) : (!fir.class<!fir.ptr<!fir.array<?x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>>, !fir.shift<1>) -> !fir.class<!fir.array<?x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>> |
| 445 |
! CHECK: %[[BOUND_ARRAY:.*]] = fir.alloca !fir.array<2x1xi64> |
| 446 |
! CHECK: %[[ARRAY:.*]] = fir.undefined !fir.array<2x1xi64> |
| 447 |
! CHECK: %[[ARRAY0:.*]] = fir.insert_value %[[ARRAY]], %[[C0]], [0 : index, 0 : index] : (!fir.array<2x1xi64>, i64) -> !fir.array<2x1xi64> |
| 448 |
! CHECK: %[[ARRAY1:.*]] = fir.insert_value %[[ARRAY0]], %[[C99]], [1 : index, 0 : index] : (!fir.array<2x1xi64>, i64) -> !fir.array<2x1xi64> |
| 449 |
! CHECK: fir.store %[[ARRAY1]] to %[[BOUND_ARRAY]] : !fir.ref<!fir.array<2x1xi64>> |
| 450 |
! CHECK: %[[C1:.*]] = arith.constant 1 : index |
| 451 |
! CHECK: %[[C2:.*]] = arith.constant 2 : index |
| 452 |
! CHECK: %[[BOUND_ARRAY_SHAPE:.*]] = fir.shape %[[C2]], %[[C1]] : (index, index) -> !fir.shape<2> |
| 453 |
! CHECK: %[[BOXED_BOUND_ARRAY:.*]] = fir.embox %[[BOUND_ARRAY]](%[[BOUND_ARRAY_SHAPE]]) : (!fir.ref<!fir.array<2x1xi64>>, !fir.shape<2>) -> !fir.box<!fir.array<2x1xi64>> |
| 454 |
! CHECK: %[[ARG0:.*]] = fir.convert %[[Q]] : (!fir.ref<!fir.class<!fir.ptr<!fir.array<?x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>>>) -> !fir.ref<!fir.box<none>> |
| 455 |
! CHECK: %[[ARG1:.*]] = fir.convert %[[REBOX_A]] : (!fir.class<!fir.array<?x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>) -> !fir.box<none> |
| 456 |
! CHECK: %[[ARG2:.*]] = fir.convert %[[BOXED_BOUND_ARRAY]] : (!fir.box<!fir.array<2x1xi64>>) -> !fir.box<none> |
| 457 |
! CHECK: %{{.*}} = fir.call @_FortranAPointerAssociateRemapping(%[[ARG0]], %[[ARG1]], %[[ARG2]], %{{.*}}, %{{.*}}) {{.*}} : (!fir.ref<!fir.box<none>>, !fir.box<none>, !fir.box<none>, !fir.ref<i8>, i32) -> none |
| 458 |
|
| 459 |
subroutine pointer_assign_lower_bounds() |
| 460 |
class(p1), allocatable, target :: a(:) |
| 461 |
class(p1), pointer :: p(:) |
| 462 |
allocate(a(100)) |
| 463 |
p(-50:) => a |
| 464 |
end subroutine |
| 465 |
|
| 466 |
! CHECK-LABEL: func.func @_QMpolymorphic_testPpointer_assign_lower_bounds() { |
| 467 |
! CHECK: %[[A:.*]] = fir.alloca !fir.class<!fir.heap<!fir.array<?x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>> {bindc_name = "a", fir.target, uniq_name = "_QMpolymorphic_testFpointer_assign_lower_boundsEa"} |
| 468 |
! CHECK: %[[P:.*]] = fir.alloca !fir.class<!fir.ptr<!fir.array<?x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>> {bindc_name = "p", uniq_name = "_QMpolymorphic_testFpointer_assign_lower_boundsEp"} |
| 469 |
! CHECK: %[[LB:.*]] = arith.constant -50 : i64 |
| 470 |
! CHECK: %[[REBOX_A:.*]] = fir.rebox %21(%23) : (!fir.class<!fir.heap<!fir.array<?x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>>, !fir.shift<1>) -> !fir.class<!fir.array<?x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>> |
| 471 |
! CHECK: %[[LBOUND_ARRAY:.*]] = fir.alloca !fir.array<1xi64> |
| 472 |
! CHECK: %[[ARRAY:.*]] = fir.undefined !fir.array<1xi64> |
| 473 |
! CHECK: %[[ARRAY0:.*]] = fir.insert_value %[[ARRAY]], %[[LB]], [0 : index] : (!fir.array<1xi64>, i64) -> !fir.array<1xi64> |
| 474 |
! CHECK: fir.store %[[ARRAY0]] to %[[LBOUND_ARRAY]] : !fir.ref<!fir.array<1xi64>> |
| 475 |
! CHECK: %[[C1:.*]] = arith.constant 1 : index |
| 476 |
! CHECK: %[[LBOUND_ARRAY_SHAPE:.*]] = fir.shape %[[C1]] : (index) -> !fir.shape<1> |
| 477 |
! CHECK: %[[LBOUND_ARRAY_BOXED:.*]] = fir.embox %[[LBOUND_ARRAY]](%[[LBOUND_ARRAY_SHAPE]]) : (!fir.ref<!fir.array<1xi64>>, !fir.shape<1>) -> !fir.box<!fir.array<1xi64>> |
| 478 |
! CHECK: %[[P_BOX_NONE:.*]] = fir.convert %[[P]] : (!fir.ref<!fir.class<!fir.ptr<!fir.array<?x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>>>) -> !fir.ref<!fir.box<none>> |
| 479 |
! CHECK: %[[A_BOX_NONE:.*]] = fir.convert %[[REBOX_A]] : (!fir.class<!fir.array<?x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>) -> !fir.box<none> |
| 480 |
! CHECK: %[[LBOUNDS_BOX_NONE:.*]] = fir.convert %[[LBOUND_ARRAY_BOXED]] : (!fir.box<!fir.array<1xi64>>) -> !fir.box<none> |
| 481 |
! CHECK: %{{.*}} = fir.call @_FortranAPointerAssociateLowerBounds(%[[P_BOX_NONE]], %[[A_BOX_NONE]], %[[LBOUNDS_BOX_NONE]]) {{.*}} : (!fir.ref<!fir.box<none>>, !fir.box<none>, !fir.box<none>) -> none |
| 482 |
|
| 483 |
subroutine test_elemental_assign() |
| 484 |
type(p1) :: pa(3) |
| 485 |
pa = [ 1, 2, 3 ] |
| 486 |
end subroutine |
| 487 |
|
| 488 |
! CHECK-LABEL: func.func @_QMpolymorphic_testPtest_elemental_assign() { |
| 489 |
! CHECK: %[[INT:.*]] = fir.alloca i32 |
| 490 |
! CHECK: %[[C3_0:.*]] = arith.constant 3 : index |
| 491 |
! CHECK: %[[PA:.*]] = fir.alloca !fir.array<3x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>> {bindc_name = "pa", uniq_name = "_QMpolymorphic_testFtest_elemental_assignEpa"} |
| 492 |
! CHECK: %[[SHAPE:.*]] = fir.shape %[[C3_0]] : (index) -> !fir.shape<1> |
| 493 |
! CHECK: %[[LOAD_PA:.*]] = fir.array_load %[[PA]](%[[SHAPE]]) : (!fir.ref<!fir.array<3x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>, !fir.shape<1>) -> !fir.array<3x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>> |
| 494 |
! CHECK: %[[ADDR_INT:.*]] = fir.address_of(@_QQro.3xi4.{{.*}}) : !fir.ref<!fir.array<3xi32>> |
| 495 |
! CHECK: %[[C3:.*]] = arith.constant 3 : index |
| 496 |
! CHECK: %[[SHAPE:.*]] = fir.shape %[[C3]] : (index) -> !fir.shape<1> |
| 497 |
! CHECK: %[[LOAD_INT_ARRAY:.*]] = fir.array_load %[[ADDR_INT]](%[[SHAPE]]) : (!fir.ref<!fir.array<3xi32>>, !fir.shape<1>) -> !fir.array<3xi32> |
| 498 |
! CHECK: %[[C1:.*]] = arith.constant 1 : index |
| 499 |
! CHECK: %[[C0:.*]] = arith.constant 0 : index |
| 500 |
! CHECK: %[[UB:.*]] = arith.subi %[[C3_0]], %[[C1]] : index |
| 501 |
! CHECK: %[[DO_RES:.*]] = fir.do_loop %[[ARG0:.*]] = %[[C0]] to %[[UB]] step %[[C1]] unordered iter_args(%[[ARG1:.*]] = %[[LOAD_PA]]) -> (!fir.array<3x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>) { |
| 502 |
! CHECK: %[[FETCH_INT:.*]] = fir.array_fetch %[[LOAD_INT_ARRAY]], %[[ARG0]] : (!fir.array<3xi32>, index) -> i32 |
| 503 |
! CHECK: %[[ARRAY_MOD:.*]]:2 = fir.array_modify %[[ARG1]], %[[ARG0]] : (!fir.array<3x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>, index) -> (!fir.ref<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>, !fir.array<3x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>) |
| 504 |
! CHECK: %[[EMBOXED:.*]] = fir.embox %10#0 : (!fir.ref<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>) -> !fir.class<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>> |
| 505 |
! CHECK: fir.store %[[FETCH_INT]] to %[[INT]] : !fir.ref<i32> |
| 506 |
! CHECK: fir.call @_QMpolymorphic_testPassign_p1_int(%[[EMBOXED]], %[[INT]]) fastmath<contract> : (!fir.class<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>, !fir.ref<i32>) -> () |
| 507 |
! CHECK: fir.result %[[ARRAY_MOD]]#1 : !fir.array<3x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>> |
| 508 |
! CHECK: } |
| 509 |
! CHECK: fir.array_merge_store %[[LOAD_PA]], %[[DO_RES]] to %[[PA]] : !fir.array<3x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>, !fir.array<3x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>, !fir.ref<!fir.array<3x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>> |
| 510 |
! CHECK: return |
| 511 |
|
| 512 |
subroutine host_assoc(this) |
| 513 |
class(p1) :: this |
| 514 |
|
| 515 |
call internal |
| 516 |
contains |
| 517 |
subroutine internal |
| 518 |
print*, this%a, this%b |
| 519 |
end subroutine |
| 520 |
end subroutine |
| 521 |
|
| 522 |
! CHECK-LABEL: func.func private @_QMpolymorphic_testFhost_assocPinternal( |
| 523 |
! CHECK-SAME: %[[TUPLE:.*]]: !fir.ref<tuple<!fir.class<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>> {fir.host_assoc}) attributes {fir.host_symbol = {{.*}}, llvm.linkage = #llvm.linkage<internal>} { |
| 524 |
! CHECK: %[[POS_IN_TUPLE:.*]] = arith.constant 0 : i32 |
| 525 |
! CHECK: %[[COORD_OF_CLASS:.*]] = fir.coordinate_of %[[TUPLE]], %[[POS_IN_TUPLE]] : (!fir.ref<tuple<!fir.class<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>>, i32) -> !fir.ref<!fir.class<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>> |
| 526 |
! CHECK: %[[CLASS:.*]] = fir.load %[[COORD_OF_CLASS]] : !fir.ref<!fir.class<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>> |
| 527 |
! CHECK: %[[FIELD_A:.*]] = fir.field_index a, !fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}> |
| 528 |
! CHECK: %[[COORD_A:.*]] = fir.coordinate_of %[[CLASS]], %[[FIELD_A]] : (!fir.class<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>, !fir.field) -> !fir.ref<i32> |
| 529 |
! CHECK: %[[A:.*]] = fir.load %[[COORD_A]] : !fir.ref<i32> |
| 530 |
! CHECK: %{{.*}} = fir.call @_FortranAioOutputInteger32(%{{.*}}, %[[A]]) {{.*}} : (!fir.ref<i8>, i32) -> i1 |
| 531 |
! CHECK: %[[FIELD_B:.*]] = fir.field_index b, !fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}> |
| 532 |
! CHECK: %[[COORD_B:.*]] = fir.coordinate_of %[[CLASS]], %[[FIELD_B]] : (!fir.class<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>, !fir.field) -> !fir.ref<i32> |
| 533 |
! CHECK: %[[B:.*]] = fir.load %[[COORD_B]] : !fir.ref<i32> |
| 534 |
! CHECK: %{{.*}} = fir.call @_FortranAioOutputInteger32(%{{.*}}, %[[B]]) {{.*}} : (!fir.ref<i8>, i32) -> i1 |
| 535 |
|
| 536 |
subroutine test_elemental_array() |
| 537 |
type(p1) :: p(5) |
| 538 |
print *, p%elemental_fct() |
| 539 |
end subroutine |
| 540 |
|
| 541 |
! CHECK-LABEL: func.func @_QMpolymorphic_testPtest_elemental_array() { |
| 542 |
! CHECK: %[[P:.*]] = fir.alloca !fir.array<5x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>> {bindc_name = "p", uniq_name = "_QMpolymorphic_testFtest_elemental_arrayEp"} |
| 543 |
! CHECK: %[[C5:.*]] = arith.constant 5 : index |
| 544 |
! CHECK: %[[TMP:.*]] = fir.allocmem !fir.array<5xi32> |
| 545 |
! CHECK: %[[SHAPE:.*]] = fir.shape %[[C5]] : (index) -> !fir.shape<1> |
| 546 |
! CHECK: %[[ARRAY_LOAD_TMP:.*]] = fir.array_load %[[TMP]](%[[SHAPE]]) : (!fir.heap<!fir.array<5xi32>>, !fir.shape<1>) -> !fir.array<5xi32> |
| 547 |
! CHECK: %[[C1:.*]] = arith.constant 1 : index |
| 548 |
! CHECK: %[[C0:.*]] = arith.constant 0 : index |
| 549 |
! CHECK: %[[UB:.*]] = arith.subi %[[C5]], %[[C1]] : index |
| 550 |
! CHECK: %[[LOOP_RES:.*]] = fir.do_loop %[[IND:.*]] = %[[C0]] to %[[UB]] step %[[C1]] unordered iter_args(%[[ARG1:.*]] = %[[ARRAY_LOAD_TMP]]) -> (!fir.array<5xi32>) { |
| 551 |
! CHECK: %[[COORD:.*]] = fir.coordinate_of %[[P]], %[[IND]] : (!fir.ref<!fir.array<5x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>, index) -> !fir.ref<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>> |
| 552 |
! CHECK: %[[EMBOXED:.*]] = fir.embox %[[COORD]] : (!fir.ref<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>) -> !fir.class<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>> |
| 553 |
! CHECK: %[[RES:.*]] = fir.call @_QMpolymorphic_testPelemental_fct(%[[EMBOXED]]) {{.*}} : (!fir.class<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>) -> i32 |
| 554 |
! CHECK: %[[ARR_UP:.*]] = fir.array_update %[[ARG1]], %[[RES]], %[[IND]] : (!fir.array<5xi32>, i32, index) -> !fir.array<5xi32> |
| 555 |
! CHECK: fir.result %[[ARR_UP]] : !fir.array<5xi32> |
| 556 |
! CHECK: } |
| 557 |
! CHECK: fir.array_merge_store %[[ARRAY_LOAD_TMP]], %[[LOOP_RES]] to %[[TMP]] : !fir.array<5xi32>, !fir.array<5xi32>, !fir.heap<!fir.array<5xi32>> |
| 558 |
! CHECK: %[[SHAPE:.*]] = fir.shape %[[C5]] : (index) -> !fir.shape<1> |
| 559 |
! CHECK: %[[EMBOXED_TMP:.*]] = fir.embox %[[TMP]](%[[SHAPE]]) : (!fir.heap<!fir.array<5xi32>>, !fir.shape<1>) -> !fir.box<!fir.array<5xi32>> |
| 560 |
! CHECK: %[[BOX_NONE:.*]] = fir.convert %[[EMBOXED_TMP]] : (!fir.box<!fir.array<5xi32>>) -> !fir.box<none> |
| 561 |
! CHECK: %{{.*}} = fir.call @_FortranAioOutputDescriptor(%{{.*}}, %[[BOX_NONE]]) {{.*}} : (!fir.ref<i8>, !fir.box<none>) -> i1 |
| 562 |
! CHECK: fir.freemem %[[TMP]] : !fir.heap<!fir.array<5xi32>> |
| 563 |
|
| 564 |
subroutine test_elemental_poly_array(p) |
| 565 |
class(p1) :: p(5) |
| 566 |
print *, p%elemental_fct() |
| 567 |
end subroutine |
| 568 |
|
| 569 |
! CHECK-LABEL: func.func @_QMpolymorphic_testPtest_elemental_poly_array( |
| 570 |
! CHECK-SAME: %[[P:.*]]: !fir.class<!fir.array<5x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>> {fir.bindc_name = "p"}) { |
| 571 |
! CHECK: %[[C5:.*]] = arith.constant 5 : index |
| 572 |
! CHECK: %[[TMP:.*]] = fir.allocmem !fir.array<5xi32> |
| 573 |
! CHECK: %[[SHAPE:.*]] = fir.shape %[[C5]] : (index) -> !fir.shape<1> |
| 574 |
! CHECK: %[[ARRAY_LOAD_TMP:.*]] = fir.array_load %[[TMP]](%[[SHAPE]]) : (!fir.heap<!fir.array<5xi32>>, !fir.shape<1>) -> !fir.array<5xi32> |
| 575 |
! CHECK: %[[C1:.*]] = arith.constant 1 : index |
| 576 |
! CHECK: %[[C0:.*]] = arith.constant 0 : index |
| 577 |
! CHECK: %[[UB:.*]] = arith.subi %[[C5]], %[[C1]] : index |
| 578 |
! CHECK: %[[LOOP_RES:.*]] = fir.do_loop %[[IND:.*]] = %[[C0]] to %[[UB]] step %[[C1]] unordered iter_args(%[[ARG:.*]] = %[[ARRAY_LOAD_TMP]]) -> (!fir.array<5xi32>) { |
| 579 |
! CHECK: %[[COORD:.*]] = fir.coordinate_of %[[P]], %[[IND]] : (!fir.class<!fir.array<5x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>, index) -> !fir.ref<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>> |
| 580 |
! CHECK: %[[EMBOXED:.*]] = fir.embox %[[COORD]] source_box %[[P]] : (!fir.ref<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>, !fir.class<!fir.array<5x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>) -> !fir.class<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>> |
| 581 |
! CHECK: %[[RES:.*]] = fir.dispatch "elemental_fct"(%[[EMBOXED]] : !fir.class<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>) (%[[EMBOXED]] : !fir.class<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>) -> i32 {pass_arg_pos = 0 : i32} |
| 582 |
! CHECK: %[[ARR_UP:.*]] = fir.array_update %[[ARG]], %[[RES]], %[[IND]] : (!fir.array<5xi32>, i32, index) -> !fir.array<5xi32> |
| 583 |
! CHECK: fir.result %[[ARR_UP]] : !fir.array<5xi32> |
| 584 |
! CHECK: } |
| 585 |
! CHECK: fir.array_merge_store %[[ARRAY_LOAD_TMP]], %[[LOOP_RES]] to %[[TMP]] : !fir.array<5xi32>, !fir.array<5xi32>, !fir.heap<!fir.array<5xi32>> |
| 586 |
! CHECK: %[[SHAPE:.*]] = fir.shape %[[C5]] : (index) -> !fir.shape<1> |
| 587 |
! CHECK: %[[EMBOXED_TMP:.*]] = fir.embox %[[TMP]](%[[SHAPE]]) : (!fir.heap<!fir.array<5xi32>>, !fir.shape<1>) -> !fir.box<!fir.array<5xi32>> |
| 588 |
! CHECK: %[[BOX_NONE:.*]] = fir.convert %[[EMBOXED_TMP]] : (!fir.box<!fir.array<5xi32>>) -> !fir.box<none> |
| 589 |
! CHECK: %{{.*}} = fir.call @_FortranAioOutputDescriptor(%{{.*}}, %[[BOX_NONE]]) {{.*}} : (!fir.ref<i8>, !fir.box<none>) -> i1 |
| 590 |
! CHECK: fir.freemem %[[TMP]] : !fir.heap<!fir.array<5xi32>> |
| 591 |
|
| 592 |
subroutine test_elemental_poly_array_2d(p) |
| 593 |
class(p1) :: p(5,5) |
| 594 |
print *, p%elemental_fct() |
| 595 |
end subroutine |
| 596 |
|
| 597 |
! CHECK-LABEL: func.func @_QMpolymorphic_testPtest_elemental_poly_array_2d( |
| 598 |
! CHECK-SAME: %[[P]]: !fir.class<!fir.array<5x5x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>> {fir.bindc_name = "p"}) { |
| 599 |
! CHECK: %[[C5:.*]] = arith.constant 5 : index |
| 600 |
! CHECK: %[[C5_0:.*]] = arith.constant 5 : index |
| 601 |
! CHECK: %[[TMP:.*]] = fir.allocmem !fir.array<5x5xi32> |
| 602 |
! CHECK: %[[SHAPE:.*]] = fir.shape %[[C5]], %[[C5_0]] : (index, index) -> !fir.shape<2> |
| 603 |
! CHECK: %[[ARRAY_LOAD_TMP:.*]] = fir.array_load %[[TMP]](%[[SHAPE]]) : (!fir.heap<!fir.array<5x5xi32>>, !fir.shape<2>) -> !fir.array<5x5xi32> |
| 604 |
! CHECK: %[[C1:.*]] = arith.constant 1 : index |
| 605 |
! CHECK: %[[C0:.*]] = arith.constant 0 : index |
| 606 |
! CHECK: %[[UB0:.*]] = arith.subi %[[C5]], %[[C1]] : index |
| 607 |
! CHECK: %[[UB1:.*]] = arith.subi %[[C5_0]], %[[C1]] : index |
| 608 |
! CHECK: %[[LOOP_RES:.*]] = fir.do_loop %[[IND0:.*]] = %[[C0]] to %[[UB1]] step %[[C1]] unordered iter_args(%[[ARG:.*]] = %[[ARRAY_LOAD_TMP]]) -> (!fir.array<5x5xi32>) { |
| 609 |
! CHECK: %[[LOOP_RES0:.*]] = fir.do_loop %[[IND1:.*]] = %[[C0]] to %[[UB0]] step %[[C1]] unordered iter_args(%[[ARG0:.*]] = %[[ARG]]) -> (!fir.array<5x5xi32>) { |
| 610 |
! CHECK: %[[COORD:.*]] = fir.coordinate_of %[[P]], %[[IND1]], %[[IND0]] : (!fir.class<!fir.array<5x5x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>, index, index) -> !fir.ref<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>> |
| 611 |
! CHECK: %[[EMBOXED:.*]] = fir.embox %[[COORD]] source_box %[[P]] : (!fir.ref<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>, !fir.class<!fir.array<5x5x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>) -> !fir.class<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>> |
| 612 |
! CHECK: %[[RES:.*]] = fir.dispatch "elemental_fct"(%[[EMBOXED]] : !fir.class<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>) (%[[EMBOXED]] : !fir.class<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>) -> i32 {pass_arg_pos = 0 : i32} |
| 613 |
! CHECK: %[[ARR_UP:.*]] = fir.array_update %[[ARG0]], %[[RES]], %[[IND1]], %[[IND0]] : (!fir.array<5x5xi32>, i32, index, index) -> !fir.array<5x5xi32> |
| 614 |
! CHECK: fir.result %[[ARR_UP]] : !fir.array<5x5xi32> |
| 615 |
! CHECK: } |
| 616 |
! CHECK: fir.result %[[LOOP_RES0]] : !fir.array<5x5xi32> |
| 617 |
! CHECK: } |
| 618 |
! CHECK: fir.array_merge_store %[[ARRAY_LOAD_TMP]], %[[LOOP_RES]] to %[[TMP]] : !fir.array<5x5xi32>, !fir.array<5x5xi32>, !fir.heap<!fir.array<5x5xi32>> |
| 619 |
! CHECK: %[[SHAPE:.*]] = fir.shape %[[C5]], %[[C5_0]] : (index, index) -> !fir.shape<2> |
| 620 |
! CHECK: %[[EMBOXED_TMP:.*]] = fir.embox %[[TMP]](%[[SHAPE]]) : (!fir.heap<!fir.array<5x5xi32>>, !fir.shape<2>) -> !fir.box<!fir.array<5x5xi32>> |
| 621 |
! CHECK: %[[BOX_NONE:.*]] = fir.convert %[[EMBOXED_TMP]] : (!fir.box<!fir.array<5x5xi32>>) -> !fir.box<none> |
| 622 |
! CHECK: %{{.*}} = fir.call @_FortranAioOutputDescriptor(%{{.*}}, %[[BOX_NONE]]) fastmath<contract> : (!fir.ref<i8>, !fir.box<none>) -> i1 |
| 623 |
! CHECK: fir.freemem %[[TMP]] : !fir.heap<!fir.array<5x5xi32>> |
| 624 |
|
| 625 |
subroutine test_elemental_sub_array() |
| 626 |
type(p1) :: t(10) |
| 627 |
call t%elemental_sub() |
| 628 |
call t%elemental_sub_pass(2) |
| 629 |
end subroutine |
| 630 |
|
| 631 |
! CHECK-LABEL: func.func @_QMpolymorphic_testPtest_elemental_sub_array() { |
| 632 |
! CHECK: %[[C10:.*]] = arith.constant 10 : index |
| 633 |
! CHECK: %[[T:.*]] = fir.alloca !fir.array<10x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>> {bindc_name = "t", uniq_name = "_QMpolymorphic_testFtest_elemental_sub_arrayEt"} |
| 634 |
! CHECK: %[[C1:.*]] = arith.constant 1 : index |
| 635 |
! CHECK: %[[C0:.*]] = arith.constant 0 : index |
| 636 |
! CHECK: %[[UB:.*]] = arith.subi %[[C10]], %[[C1]] : index |
| 637 |
! CHECK: fir.do_loop %[[IND:.*]] = %[[C0]] to %[[UB]] step %[[C1]] { |
| 638 |
! CHECK: %[[COORD:.*]] = fir.coordinate_of %[[T]], %[[IND]] : (!fir.ref<!fir.array<10x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>, index) -> !fir.ref<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>> |
| 639 |
! CHECK: %[[EMBOXED:.*]] = fir.embox %[[COORD]] : (!fir.ref<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>) -> !fir.class<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>> |
| 640 |
! CHECK: fir.call @_QMpolymorphic_testPelemental_sub(%[[EMBOXED]]) {{.*}} : (!fir.class<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>) -> () |
| 641 |
! CHECK: } |
| 642 |
! CHECK: %[[C1:.*]] = arith.constant 1 : index |
| 643 |
! CHECK: %[[C0:.*]] = arith.constant 0 : index |
| 644 |
! CHECK: %[[UB:.*]] = arith.subi %[[C10]], %[[C1]] : index |
| 645 |
! CHECK: fir.do_loop %[[IND:.*]] = %[[C0]] to %[[UB]] step %[[C1]] { |
| 646 |
! CHECK: %[[COORD:.*]] = fir.coordinate_of %[[T]], %[[IND]] : (!fir.ref<!fir.array<10x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>, index) -> !fir.ref<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>> |
| 647 |
! CHECK: %[[EMBOXED:.*]] = fir.embox %[[COORD]] : (!fir.ref<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>) -> !fir.class<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>> |
| 648 |
! CHECK: fir.call @_QMpolymorphic_testPelemental_sub_pass(%{{.*}}, %[[EMBOXED]]) {{.*}} : (!fir.ref<i32>, !fir.class<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>) -> () |
| 649 |
! CHECK: } |
| 650 |
|
| 651 |
subroutine test_elemental_sub_poly_array(p) |
| 652 |
class(p1) :: p(10) |
| 653 |
call p%elemental_sub() |
| 654 |
call p%elemental_sub_pass(3) |
| 655 |
end subroutine |
| 656 |
|
| 657 |
! CHECK-LABEL: func.func @_QMpolymorphic_testPtest_elemental_sub_poly_array( |
| 658 |
! CHECK-SAME: %[[P:.*]]: !fir.class<!fir.array<10x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>> {fir.bindc_name = "p"}) { |
| 659 |
! CHECK: %[[C10:.*]] = arith.constant 10 : index |
| 660 |
! CHECK: %[[C1:.*]] = arith.constant 1 : index |
| 661 |
! CHECK: %[[C0:.*]] = arith.constant 0 : index |
| 662 |
! CHECK: %[[UB:.*]] = arith.subi %[[C10]], %[[C1]] : index |
| 663 |
! CHECK: fir.do_loop %[[IND:.*]] = %[[C0]] to %[[UB]] step %[[C1]] { |
| 664 |
! CHECK: %[[COORD:.*]] = fir.coordinate_of %[[P]], %[[IND]] : (!fir.class<!fir.array<10x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>, index) -> !fir.ref<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>> |
| 665 |
! CHECK: %[[EMBOXED:.*]] = fir.embox %[[COORD]] source_box %[[P]] : (!fir.ref<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>, !fir.class<!fir.array<10x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>) -> !fir.class<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>> |
| 666 |
! CHECK: fir.dispatch "elemental_sub"(%[[EMBOXED]] : !fir.class<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>) (%[[EMBOXED]] : !fir.class<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>) {pass_arg_pos = 0 : i32} |
| 667 |
! CHECK: } |
| 668 |
! CHECK: %[[C1:.*]] = arith.constant 1 : index |
| 669 |
! CHECK: %[[C0:.*]] = arith.constant 0 : index |
| 670 |
! CHECK: %[[UB:.*]] = arith.subi %[[C10]], %[[C1]] : index |
| 671 |
! CHECK: fir.do_loop %[[IND:.*]] = %[[C0]] to %[[UB]] step %[[C1]] { |
| 672 |
! CHECK: %[[COORD:.*]] = fir.coordinate_of %[[P]], %[[IND]] : (!fir.class<!fir.array<10x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>, index) -> !fir.ref<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>> |
| 673 |
! CHECK: %[[EMBOXED:.*]] = fir.embox %[[COORD]] source_box %[[P]] : (!fir.ref<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>, !fir.class<!fir.array<10x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>) -> !fir.class<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>> |
| 674 |
! CHECK: fir.dispatch "elemental_sub_pass"(%[[EMBOXED]] : !fir.class<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>) (%{{.*}}, %[[EMBOXED]] : !fir.ref<i32>, !fir.class<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>) {pass_arg_pos = 1 : i32} |
| 675 |
! CHECK: } |
| 676 |
|
| 677 |
subroutine test_elemental_sub_array_assumed(t) |
| 678 |
type(p1) :: t(:) |
| 679 |
call t%elemental_sub() |
| 680 |
call t%elemental_sub_pass(4) |
| 681 |
end subroutine |
| 682 |
|
| 683 |
! CHECK-LABEL: func.func @_QMpolymorphic_testPtest_elemental_sub_array_assumed( |
| 684 |
! CHECK-SAME: %[[T:.*]]: !fir.box<!fir.array<?x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>> {fir.bindc_name = "t"}) { |
| 685 |
! CHECK: %[[C0:.*]] = arith.constant 0 : index |
| 686 |
! CHECK: %[[T_DIMS:.*]]:3 = fir.box_dims %[[T]], %[[C0]] : (!fir.box<!fir.array<?x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>, index) -> (index, index, index) |
| 687 |
! CHECK: %[[C1:.*]] = arith.constant 1 : index |
| 688 |
! CHECK: %[[C0:.*]] = arith.constant 0 : index |
| 689 |
! CHECK: %[[UB:.*]] = arith.subi %[[T_DIMS]]#1, %[[C1]] : index |
| 690 |
! CHECK: fir.do_loop %[[IND:.*]] = %[[C0]] to %[[UB]] step %[[C1]] { |
| 691 |
! CHECK: %[[COORD:.*]] = fir.coordinate_of %[[T]], %[[IND]] : (!fir.box<!fir.array<?x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>, index) -> !fir.ref<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>> |
| 692 |
! CHECK: %[[EMBOXED:.*]] = fir.embox %[[COORD]] : (!fir.ref<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>) -> !fir.class<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>> |
| 693 |
! CHECK: fir.call @_QMpolymorphic_testPelemental_sub(%[[EMBOXED]]) {{.*}} : (!fir.class<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>) -> () |
| 694 |
! CHECK: %[[C0:.*]] = arith.constant 0 : index |
| 695 |
! CHECK: %[[T_DIMS:.*]]:3 = fir.box_dims %[[T]], %[[C0]] : (!fir.box<!fir.array<?x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>, index) -> (index, index, index) |
| 696 |
! CHECK: %[[C1:.*]] = arith.constant 1 : index |
| 697 |
! CHECK: %[[C0:.*]] = arith.constant 0 : index |
| 698 |
! CHECK: %[[UB:.*]] = arith.subi %[[T_DIMS]]#1, %[[C1]] : index |
| 699 |
! CHECK: fir.do_loop %[[IND:.*]] = %[[C0]] to %[[UB]] step %[[C1]] { |
| 700 |
! CHECK: %[[COORD:.*]] = fir.coordinate_of %[[T]], %[[IND]] : (!fir.box<!fir.array<?x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>, index) -> !fir.ref<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>> |
| 701 |
! CHECK: %[[EMBOXED:.*]] = fir.embox %[[COORD]] : (!fir.ref<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>) -> !fir.class<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>> |
| 702 |
! CHECK: fir.call @_QMpolymorphic_testPelemental_sub_pass(%{{.*}}, %[[EMBOXED]]) {{.*}} : (!fir.ref<i32>, !fir.class<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>) -> () |
| 703 |
! CHECK: } |
| 704 |
|
| 705 |
subroutine test_elemental_sub_poly_array_assumed(p) |
| 706 |
class(p1) :: p(:) |
| 707 |
call p%elemental_sub() |
| 708 |
call p%elemental_sub_pass(5) |
| 709 |
end subroutine |
| 710 |
|
| 711 |
! CHECK-LABEL: func.func @_QMpolymorphic_testPtest_elemental_sub_poly_array_assumed( |
| 712 |
! CHECK-SAME: %[[P:.*]]: !fir.class<!fir.array<?x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>> {fir.bindc_name = "p"}) { |
| 713 |
! CHECK: %[[C0:.*]] = arith.constant 0 : index |
| 714 |
! CHECK: %[[P_DIMS:.*]]:3 = fir.box_dims %[[P]], %[[C0]] : (!fir.class<!fir.array<?x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>, index) -> (index, index, index) |
| 715 |
! CHECK: %[[C1:.*]] = arith.constant 1 : index |
| 716 |
! CHECK: %[[C0:.*]] = arith.constant 0 : index |
| 717 |
! CHECK: %[[UB:.*]] = arith.subi %[[P_DIMS]]#1, %[[C1]] : index |
| 718 |
! CHECK: fir.do_loop %[[IND:.*]] = %[[C0]] to %[[UB]] step %[[C1]] { |
| 719 |
! CHECK: %[[COORD:.*]] = fir.coordinate_of %[[P]], %[[IND]] : (!fir.class<!fir.array<?x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>, index) -> !fir.ref<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>> |
| 720 |
! CHECK: %[[EMBOXED:.*]] = fir.embox %[[COORD]] source_box %[[P]] : (!fir.ref<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>, !fir.class<!fir.array<?x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>) -> !fir.class<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>> |
| 721 |
! CHECK: fir.dispatch "elemental_sub"(%[[EMBOXED]] : !fir.class<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>) (%[[EMBOXED]] : !fir.class<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>) {pass_arg_pos = 0 : i32} |
| 722 |
! CHECK: } |
| 723 |
! CHECK: %[[C0:.*]] = arith.constant 0 : index |
| 724 |
! CHECK: %[[P_DIMS:.*]]:3 = fir.box_dims %[[P]], %[[C0]] : (!fir.class<!fir.array<?x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>, index) -> (index, index, index) |
| 725 |
! CHECK: %[[C1:.*]] = arith.constant 1 : index |
| 726 |
! CHECK: %[[C0:.*]] = arith.constant 0 : index |
| 727 |
! CHECK: %[[UB:.*]] = arith.subi %[[P_DIMS]]#1, %[[C1]] : index |
| 728 |
! CHECK: fir.do_loop %[[IND:.*]] = %[[C0]] to %[[UB]] step %[[C1]] { |
| 729 |
! CHECK: %[[COORD:.*]] = fir.coordinate_of %[[P]], %[[IND]] : (!fir.class<!fir.array<?x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>, index) -> !fir.ref<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>> |
| 730 |
! CHECK: %[[EMBOXED:.*]] = fir.embox %[[COORD]] source_box %[[P]] : (!fir.ref<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>, !fir.class<!fir.array<?x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>) -> !fir.class<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>> |
| 731 |
! CHECK: fir.dispatch "elemental_sub_pass"(%[[EMBOXED]] : !fir.class<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>) (%{{.*}}, %[[EMBOXED]] : !fir.ref<i32>, !fir.class<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>) {pass_arg_pos = 1 : i32} |
| 732 |
! CHECK: } |
| 733 |
|
| 734 |
subroutine write_p1(dtv, unit, iotype, v_list, iostat, iomsg) |
| 735 |
class(p1), intent(in) :: dtv |
| 736 |
integer, intent(in) :: unit |
| 737 |
character(*), intent(in) :: iotype |
| 738 |
integer, intent(in) :: v_list(:) |
| 739 |
integer, intent(out) :: iostat |
| 740 |
character(*), intent(inout) :: iomsg |
| 741 |
! dummy subroutine for testing purpose |
| 742 |
end subroutine |
| 743 |
|
| 744 |
subroutine read_p1(dtv, unit, iotype, v_list, iostat, iomsg) |
| 745 |
class(p1), intent(inout) :: dtv |
| 746 |
integer, intent(in) :: unit |
| 747 |
character(*), intent(in) :: iotype |
| 748 |
integer, intent(in) :: v_list(:) |
| 749 |
integer, intent(out) :: iostat |
| 750 |
character(*), intent(inout) :: iomsg |
| 751 |
! dummy subroutine for testing purpose |
| 752 |
end subroutine |
| 753 |
|
| 754 |
subroutine test_polymorphic_io() |
| 755 |
type(p1), target :: t |
| 756 |
class(p1), pointer :: p |
| 757 |
open(17, form='formatted', access='stream') |
| 758 |
write(17, 1) t |
| 759 |
1 Format(1X,I10) |
| 760 |
p => t |
| 761 |
rewind(17) |
| 762 |
read(17, 1) p |
| 763 |
end subroutine |
| 764 |
|
| 765 |
! CHECK-LABEL: func.func @_QMpolymorphic_testPtest_polymorphic_io() { |
| 766 |
! CHECK: %[[P:.*]] = fir.alloca !fir.class<!fir.ptr<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>> {bindc_name = "p", uniq_name = "_QMpolymorphic_testFtest_polymorphic_ioEp"} |
| 767 |
! CHECK: %[[LOAD_P:.*]] = fir.load %[[P]] : !fir.ref<!fir.class<!fir.ptr<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>> |
| 768 |
! CHECK: %[[BOX_NONE:.*]] = fir.convert %[[LOAD_P]] : (!fir.class<!fir.ptr<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>) -> !fir.box<none> |
| 769 |
! CHECK: %{{.*}} = fir.call @_FortranAioInputDerivedType(%{{.*}}, %[[BOX_NONE]], %{{.*}}) {{.*}} : (!fir.ref<i8>, !fir.box<none>, !fir.ref<none>) -> i1 |
| 770 |
|
| 771 |
function unlimited_polymorphic_alloc_array_ret() |
| 772 |
class(*), allocatable :: unlimited_polymorphic_alloc_array_ret(:) |
| 773 |
end function |
| 774 |
|
| 775 |
subroutine test_unlimited_polymorphic_alloc_array_ret() |
| 776 |
select type (a => unlimited_polymorphic_alloc_array_ret()) |
| 777 |
type is (real) |
| 778 |
print*, 'type is real' |
| 779 |
end select |
| 780 |
end subroutine |
| 781 |
|
| 782 |
! CHECK-LABEL: func.func @_QMpolymorphic_testPtest_unlimited_polymorphic_alloc_array_ret() { |
| 783 |
! CHECK: %[[RES_TMP:.*]] = fir.alloca !fir.class<!fir.heap<!fir.array<?xnone>>> {bindc_name = ".result"} |
| 784 |
! CHECK: %[[RES:.*]] = fir.call @_QMpolymorphic_testPunlimited_polymorphic_alloc_array_ret() fastmath<contract> : () -> !fir.class<!fir.heap<!fir.array<?xnone>>> |
| 785 |
! CHECK: fir.save_result %[[RES]] to %[[RES_TMP]] : !fir.class<!fir.heap<!fir.array<?xnone>>>, !fir.ref<!fir.class<!fir.heap<!fir.array<?xnone>>>> |
| 786 |
|
| 787 |
subroutine test_unlimited_polymorphic_intentout(a) |
| 788 |
class(*), intent(out) :: a |
| 789 |
end subroutine |
| 790 |
|
| 791 |
! CHECK-LABEL: func.func @_QMpolymorphic_testPtest_unlimited_polymorphic_intentout( |
| 792 |
! CHECK-SAME: %[[ARG0:.*]]: !fir.class<none> {fir.bindc_name = "a"}) { |
| 793 |
! CHECK: %[[BOX_NONE:.*]] = fir.convert %[[ARG0]] : (!fir.class<none>) -> !fir.box<none> |
| 794 |
! CHECK: %{{.*}} = fir.call @_FortranADestroy(%[[BOX_NONE]]) {{.*}} : (!fir.box<none>) -> none |
| 795 |
! CHECK: %[[BOX_NONE:.*]] = fir.convert %[[ARG0]] : (!fir.class<none>) -> !fir.box<none> |
| 796 |
! CHECK: %{{.*}} = fir.call @_FortranAInitialize(%[[BOX_NONE]], %{{.*}}, %{{.*}}) {{.*}} : (!fir.box<none>, !fir.ref<i8>, i32) -> none |
| 797 |
|
| 798 |
subroutine test_polymorphic_intentout(a) |
| 799 |
class(p1), intent(out) :: a |
| 800 |
end subroutine |
| 801 |
|
| 802 |
! CHECK-LABEL: func.func @_QMpolymorphic_testPtest_polymorphic_intentout( |
| 803 |
! CHECK-SAME: %[[ARG0:.*]]: !fir.class<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>> {fir.bindc_name = "a"}) { |
| 804 |
! CHECK: %[[BOX_NONE:.*]] = fir.convert %[[ARG0]] : (!fir.class<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>) -> !fir.box<none> |
| 805 |
! CHECK: %{{.*}} = fir.call @_FortranADestroy(%[[BOX_NONE]]) {{.*}} : (!fir.box<none>) -> none |
| 806 |
! CHECK: %[[BOX_NONE:.*]] = fir.convert %[[ARG0]] : (!fir.class<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>) -> !fir.box<none> |
| 807 |
! CHECK: %{{.*}} = fir.call @_FortranAInitialize(%[[BOX_NONE]], %{{.*}}, %{{.*}}) {{.*}} : (!fir.box<none>, !fir.ref<i8>, i32) -> none |
| 808 |
|
| 809 |
subroutine rebox_up_to_record_type(p) |
| 810 |
class(*), allocatable, target :: p(:,:) |
| 811 |
type(non_extensible), pointer :: t(:,:) |
| 812 |
t => p |
| 813 |
end subroutine |
| 814 |
|
| 815 |
! CHECK-LABEL: func.func @_QMpolymorphic_testPrebox_up_to_record_type( |
| 816 |
! CHECK-SAME: %[[P:.*]]: !fir.ref<!fir.class<!fir.heap<!fir.array<?x?xnone>>>> {fir.bindc_name = "p", fir.target}) { |
| 817 |
! CHECK: %[[T:.*]] = fir.alloca !fir.box<!fir.ptr<!fir.array<?x?x!fir.type<_QMpolymorphic_testTnon_extensible{d:i32}>>>> {bindc_name = "t", uniq_name = "_QMpolymorphic_testFrebox_up_to_record_typeEt"} |
| 818 |
! CHECK: %[[LOAD_P:.*]] = fir.load %[[P]] : !fir.ref<!fir.class<!fir.heap<!fir.array<?x?xnone>>>> |
| 819 |
! CHECK: %[[REBOX:.*]] = fir.rebox %[[LOAD_P]](%{{.*}}) : (!fir.class<!fir.heap<!fir.array<?x?xnone>>>, !fir.shift<2>) -> !fir.box<!fir.ptr<!fir.array<?x?x!fir.type<_QMpolymorphic_testTnon_extensible{d:i32}>>>> |
| 820 |
! CHECK: fir.store %[[REBOX]] to %[[T]] : !fir.ref<!fir.box<!fir.ptr<!fir.array<?x?x!fir.type<_QMpolymorphic_testTnon_extensible{d:i32}>>>>> |
| 821 |
|
| 822 |
subroutine sub_with_poly_optional(a) |
| 823 |
class(*), optional :: a |
| 824 |
end subroutine |
| 825 |
|
| 826 |
subroutine test_call_with_null() |
| 827 |
call sub_with_poly_optional(null()) |
| 828 |
end subroutine |
| 829 |
|
| 830 |
! CHECK-LABEL: func.func @_QMpolymorphic_testPtest_call_with_null() { |
| 831 |
! CHECK: %[[NULL_PTR:.*]] = fir.alloca !fir.box<!fir.ptr<none>> |
| 832 |
! CHECK: %[[NULL:.*]] = fir.zero_bits !fir.ptr<none> |
| 833 |
! CHECK: %[[NULL_BOX:.*]] = fir.embox %[[NULL]] : (!fir.ptr<none>) -> !fir.box<!fir.ptr<none>> |
| 834 |
! CHECK: fir.store %[[NULL_BOX]] to %[[NULL_PTR]] : !fir.ref<!fir.box<!fir.ptr<none>>> |
| 835 |
! CHECK: %[[BOX_NONE:.*]] = fir.load %[[NULL_PTR]] : !fir.ref<!fir.box<!fir.ptr<none>>> |
| 836 |
! CHECK: %[[BOX_ADDR:.*]] = fir.box_addr %[[BOX_NONE]] : (!fir.box<!fir.ptr<none>>) -> !fir.ptr<none> |
| 837 |
! CHECK: %[[BOX_ADDR_I64:.*]] = fir.convert %[[BOX_ADDR]] : (!fir.ptr<none>) -> i64 |
| 838 |
! CHECK: %[[C0:.*]] = arith.constant 0 : i64 |
| 839 |
! CHECK: %[[IS_ALLOCATED_OR_ASSOCIATED:.*]] = arith.cmpi ne, %[[BOX_ADDR_I64]], %[[C0]] : i64 |
| 840 |
! CHECK: %[[ABSENT:.*]] = fir.absent !fir.class<none> |
| 841 |
! CHECK: %[[PTR_LOAD2:.*]] = fir.load %[[NULL_PTR]] : !fir.ref<!fir.box<!fir.ptr<none>>> |
| 842 |
! CHECK: %[[CLASS_NONE:.*]] = fir.rebox %[[PTR_LOAD2]] : (!fir.box<!fir.ptr<none>>) -> !fir.class<none> |
| 843 |
! CHECK: %[[ARG:.*]] = arith.select %[[IS_ALLOCATED_OR_ASSOCIATED]], %[[CLASS_NONE]], %[[ABSENT]] : !fir.class<none> |
| 844 |
! CHECK: fir.call @_QMpolymorphic_testPsub_with_poly_optional(%[[ARG]]) {{.*}} : (!fir.class<none>) -> () |
| 845 |
|
| 846 |
subroutine sub_with_poly_array_optional(a) |
| 847 |
class(*), optional :: a(:) |
| 848 |
end subroutine |
| 849 |
|
| 850 |
subroutine test_call_with_pointer_to_optional() |
| 851 |
real, pointer :: p(:) |
| 852 |
call sub_with_poly_array_optional(p) |
| 853 |
end subroutine |
| 854 |
|
| 855 |
! CHECK-LABEL: func.func @_QMpolymorphic_testPtest_call_with_pointer_to_optional() { |
| 856 |
! CHECK: %[[P:.*]] = fir.alloca !fir.box<!fir.ptr<!fir.array<?xf32>>> {bindc_name = "p", uniq_name = "_QMpolymorphic_testFtest_call_with_pointer_to_optionalEp"} |
| 857 |
! CHECK: %[[IS_ALLOCATED_OR_ASSOCIATED:.*]] = arith.cmpi ne |
| 858 |
! CHECK: %[[ABSENT:.*]] = fir.absent !fir.class<!fir.array<?xnone>> |
| 859 |
! CHECK: %[[LOAD_P:.*]] = fir.load %[[P]] : !fir.ref<!fir.box<!fir.ptr<!fir.array<?xf32>>>> |
| 860 |
! CHECK: %[[REBOX:.*]] = fir.rebox %[[LOAD_P]] : (!fir.box<!fir.ptr<!fir.array<?xf32>>>) -> !fir.class<!fir.array<?xnone>> |
| 861 |
! CHECK: %[[ARG:.*]] = arith.select %[[IS_ALLOCATED_OR_ASSOCIATED]], %[[REBOX]], %[[ABSENT]] : !fir.class<!fir.array<?xnone>> |
| 862 |
! CHECK: fir.call @_QMpolymorphic_testPsub_with_poly_array_optional(%[[ARG]]) {{.*}} : (!fir.class<!fir.array<?xnone>>) -> () |
| 863 |
|
| 864 |
subroutine sub_with_real_pointer_optional(p) |
| 865 |
real, optional :: p(:) |
| 866 |
call sub_with_poly_array_optional(p) |
| 867 |
end subroutine |
| 868 |
|
| 869 |
! CHECK-LABEL: func.func @_QMpolymorphic_testPsub_with_real_pointer_optional( |
| 870 |
! CHECK-SAME: %[[P:.*]]: !fir.box<!fir.array<?xf32>> {fir.bindc_name = "p", fir.optional}) { |
| 871 |
! CHECK: %[[IS_PRESENT:.*]] = fir.is_present %[[P]] : (!fir.box<!fir.array<?xf32>>) -> i1 |
| 872 |
! CHECK: %[[BOX:.*]] = fir.if %[[IS_PRESENT]] -> (!fir.class<!fir.array<?xnone>>) { |
| 873 |
! CHECK: %[[REBOX:.*]] = fir.rebox %[[P]] : (!fir.box<!fir.array<?xf32>>) -> !fir.class<!fir.array<?xnone>> |
| 874 |
! CHECK: fir.result %[[REBOX]] : !fir.class<!fir.array<?xnone>> |
| 875 |
! CHECK: } else { |
| 876 |
! CHECK: %[[ABSENT:.*]] = fir.absent !fir.class<!fir.array<?xnone>> |
| 877 |
! CHECK: fir.result %[[ABSENT]] : !fir.class<!fir.array<?xnone>> |
| 878 |
! CHECK: } |
| 879 |
! CHECK: fir.call @_QMpolymorphic_testPsub_with_poly_array_optional(%[[BOX]]) {{.*}} : (!fir.class<!fir.array<?xnone>>) -> () |
| 880 |
|
| 881 |
subroutine pass_poly_pointer_optional(p) |
| 882 |
class(p1), pointer, optional :: p |
| 883 |
end subroutine |
| 884 |
|
| 885 |
subroutine test_poly_pointer_null() |
| 886 |
call pass_poly_pointer_optional(null()) |
| 887 |
end subroutine |
| 888 |
|
| 889 |
! CHECK-LABEL: func.func @_QMpolymorphic_testPtest_poly_pointer_null() { |
| 890 |
! CHECK: %[[ALLOCA:.*]] = fir.alloca !fir.class<!fir.ptr<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>> |
| 891 |
! CHECK: %[[ZERO:.*]] = fir.zero_bits !fir.ptr<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>> |
| 892 |
! CHECK: %[[EMBOX:.*]] = fir.embox %[[ZERO]] : (!fir.ptr<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>) -> !fir.class<!fir.ptr<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>> |
| 893 |
! CHECK: fir.store %[[EMBOX]] to %[[ALLOCA]] : !fir.ref<!fir.class<!fir.ptr<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>> |
| 894 |
! CHECK: fir.call @_QMpolymorphic_testPpass_poly_pointer_optional(%[[ALLOCA]]) fastmath<contract> : (!fir.ref<!fir.class<!fir.ptr<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>>) -> () |
| 895 |
|
| 896 |
subroutine test_poly_array_component_output(p) |
| 897 |
class(p1), pointer :: p(:) |
| 898 |
print*, p(:)%a |
| 899 |
end subroutine |
| 900 |
|
| 901 |
! CHECK-LABEL: func.func @_QMpolymorphic_testPtest_poly_array_component_output( |
| 902 |
! CHECK-SAME: %[[P]]: !fir.ref<!fir.class<!fir.ptr<!fir.array<?x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>>> {fir.bindc_name = "p"}) { |
| 903 |
! CHECK: %[[LOAD_P:.*]] = fir.load %[[P]] : !fir.ref<!fir.class<!fir.ptr<!fir.array<?x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>>> |
| 904 |
! CHECK: %[[FIELD_INDEX_A:.*]] = fir.field_index a, !fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}> |
| 905 |
! CHECK: %[[SLICE:.*]] = fir.slice %{{.*}}#0, %{{.*}}, %{{.*}} path %[[FIELD_INDEX_A]] : (index, index, index, !fir.field) -> !fir.slice<1> |
| 906 |
! CHECK: %[[REBOX:.*]] = fir.rebox %[[LOAD_P]](%{{.*}}) [%[[SLICE]]] : (!fir.class<!fir.ptr<!fir.array<?x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>>, !fir.shift<1>, !fir.slice<1>) -> !fir.box<!fir.array<?xi32>> |
| 907 |
! CHECK: %[[BOX_NONE:.*]] = fir.convert %[[REBOX]] : (!fir.box<!fir.array<?xi32>>) -> !fir.box<none> |
| 908 |
! CHECK: %{{.*}} = fir.call @_FortranAioOutputDescriptor(%{{.*}}, %[[BOX_NONE]]) fastmath<contract> : (!fir.ref<i8>, !fir.box<none>) -> i1 |
| 909 |
|
| 910 |
subroutine opt_int(i) |
| 911 |
integer, optional, intent(in) :: i |
| 912 |
call opt_up(i) |
| 913 |
end subroutine |
| 914 |
|
| 915 |
! CHECK-LABEL: func.func @_QMpolymorphic_testPopt_int( |
| 916 |
! CHECK-SAME: %[[ARG0:.*]]: !fir.ref<i32> {fir.bindc_name = "i", fir.optional}) { |
| 917 |
! CHECK: %[[IS_PRESENT:.*]] = fir.is_present %[[ARG0]] : (!fir.ref<i32>) -> i1 |
| 918 |
! CHECK: %[[ARG:.*]] = fir.if %[[IS_PRESENT]] -> (!fir.class<none>) { |
| 919 |
! CHECK: %[[EMBOXED:.*]] = fir.embox %[[ARG0]] : (!fir.ref<i32>) -> !fir.class<none> |
| 920 |
! CHECK: fir.result %[[EMBOXED]] : !fir.class<none> |
| 921 |
! CHECK: } else { |
| 922 |
! CHECK: %[[ABSENT:.*]] = fir.absent !fir.class<none> |
| 923 |
! CHECK: fir.result %[[ABSENT]] : !fir.class<none> |
| 924 |
! CHECK: } |
| 925 |
! CHECK: fir.call @_QMpolymorphic_testPopt_up(%[[ARG]]) fastmath<contract> : (!fir.class<none>) -> () |
| 926 |
|
| 927 |
subroutine opt_up(up) |
| 928 |
class(*), optional, intent(in) :: up |
| 929 |
end subroutine |
| 930 |
|
| 931 |
function rhs() |
| 932 |
class(p1), pointer :: rhs |
| 933 |
end function |
| 934 |
|
| 935 |
subroutine test_rhs_assign(a) |
| 936 |
type(p1) :: a |
| 937 |
a = rhs() |
| 938 |
end subroutine |
| 939 |
|
| 940 |
! CHECK-LABEL: func.func @_QMpolymorphic_testPtest_rhs_assign( |
| 941 |
! CHECK-SAME: %[[ARG0:.*]]: !fir.ref<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>> {fir.bindc_name = "a"}) { |
| 942 |
! CHECK: %[[RES:.*]] = fir.alloca !fir.class<!fir.ptr<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>> {bindc_name = ".result"} |
| 943 |
! CHECK: %[[A:.*]] = fir.embox %[[ARG0]] : (!fir.ref<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>) -> !fir.box<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>> |
| 944 |
! CHECK: %[[LOAD_RES:.*]] = fir.load %[[RES]] : !fir.ref<!fir.class<!fir.ptr<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>> |
| 945 |
! CHECK: %[[A_NONE:.*]] = fir.convert %[[A]] : (!fir.box<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>) -> !fir.ref<!fir.box<none>> |
| 946 |
! CHECK: %[[RES_NONE:.*]] = fir.convert %[[LOAD_RES]] : (!fir.class<!fir.ptr<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>) -> !fir.box<none> |
| 947 |
! CHECK: %{{.*}} = fir.call @_FortranAAssign(%[[A_NONE]], %[[RES_NONE]], %{{.*}}, %{{.*}}) {{.*}} : (!fir.ref<!fir.box<none>>, !fir.box<none>, !fir.ref<i8>, i32) -> none |
| 948 |
|
| 949 |
subroutine type_with_polymorphic_components(a, b) |
| 950 |
type(p4) :: a, b |
| 951 |
a = b |
| 952 |
end subroutine |
| 953 |
|
| 954 |
! CHECK-LABEL: func.func @_QMpolymorphic_testPtype_with_polymorphic_components( |
| 955 |
! CHECK-SAME: %[[A:.*]]: !fir.ref<!fir.type<_QMpolymorphic_testTp4{a:!fir.class<!fir.heap<!fir.array<?x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>>}>> {fir.bindc_name = "a"}, %[[B:.*]]: !fir.ref<!fir.type<_QMpolymorphic_testTp4{a:!fir.class<!fir.heap<!fir.array<?x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>>}>> {fir.bindc_name = "b"}) { |
| 956 |
! CHECK: %[[ALLOCA:.*]] = fir.alloca !fir.box<!fir.type<_QMpolymorphic_testTp4{a:!fir.class<!fir.heap<!fir.array<?x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>>}>> |
| 957 |
! CHECK: %[[EMBOX_A:.*]] = fir.embox %[[A]] : (!fir.ref<!fir.type<_QMpolymorphic_testTp4{a:!fir.class<!fir.heap<!fir.array<?x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>>}>>) -> !fir.box<!fir.type<_QMpolymorphic_testTp4{a:!fir.class<!fir.heap<!fir.array<?x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>>}>> |
| 958 |
! CHECK: %[[EMBOX_B:.*]] = fir.embox %[[B]] : (!fir.ref<!fir.type<_QMpolymorphic_testTp4{a:!fir.class<!fir.heap<!fir.array<?x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>>}>>) -> !fir.box<!fir.type<_QMpolymorphic_testTp4{a:!fir.class<!fir.heap<!fir.array<?x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>>}>> |
| 959 |
! CHECK: fir.store %[[EMBOX_A]] to %[[ALLOCA]] : !fir.ref<!fir.box<!fir.type<_QMpolymorphic_testTp4{a:!fir.class<!fir.heap<!fir.array<?x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>>}>>> |
| 960 |
! CHECK: %[[BOX_NONE1:.*]] = fir.convert %[[ALLOCA]] : (!fir.ref<!fir.box<!fir.type<_QMpolymorphic_testTp4{a:!fir.class<!fir.heap<!fir.array<?x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>>}>>>) -> !fir.ref<!fir.box<none>> |
| 961 |
! CHECK: %[[BOX_NONE2:.*]] = fir.convert %[[EMBOX_B]] : (!fir.box<!fir.type<_QMpolymorphic_testTp4{a:!fir.class<!fir.heap<!fir.array<?x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>>}>>) -> !fir.box<none> |
| 962 |
! CHECK: %{{.*}} = fir.call @_FortranAAssign(%[[BOX_NONE1]], %[[BOX_NONE2]], %{{.*}}, %{{.*}}) {{.*}} : (!fir.ref<!fir.box<none>>, !fir.box<none>, !fir.ref<i8>, i32) -> none |
| 963 |
|
| 964 |
subroutine up_pointer(p) |
| 965 |
class(*), pointer, intent(in) :: p |
| 966 |
end subroutine |
| 967 |
|
| 968 |
subroutine test_char_to_up_pointer(c) |
| 969 |
character(*), target :: c |
| 970 |
call up_pointer(c) |
| 971 |
end subroutine |
| 972 |
|
| 973 |
! CHECK-LABEL: func.func @_QMpolymorphic_testPtest_char_to_up_pointer( |
| 974 |
! CHECK-SAME: %[[C:.*]]: !fir.boxchar<1> {fir.bindc_name = "c", fir.target}) { |
| 975 |
! CHECK: %[[NEW_BOX:.*]] = fir.alloca !fir.class<!fir.ptr<none>> |
| 976 |
! CHECK: %[[UNBOXCHAR:.*]]:2 = fir.unboxchar %arg0 : (!fir.boxchar<1>) -> (!fir.ref<!fir.char<1,?>>, index) |
| 977 |
! CHECK: %[[EMBOX:.*]] = fir.embox %[[UNBOXCHAR]]#0 typeparams %[[UNBOXCHAR]]#1 : (!fir.ref<!fir.char<1,?>>, index) -> !fir.class<!fir.ptr<none>> |
| 978 |
! CHECK: fir.store %[[EMBOX]] to %[[NEW_BOX]] : !fir.ref<!fir.class<!fir.ptr<none>>> |
| 979 |
! CHECK: fir.call @_QMpolymorphic_testPup_pointer(%[[NEW_BOX]]) {{.*}} : (!fir.ref<!fir.class<!fir.ptr<none>>>) -> () |
| 980 |
|
| 981 |
subroutine move_alloc_poly(a, b) |
| 982 |
class(p1), allocatable :: a, b |
| 983 |
|
| 984 |
call move_alloc(a, b) |
| 985 |
end subroutine |
| 986 |
|
| 987 |
! CHECK-LABEL: func.func @_QMpolymorphic_testPmove_alloc_poly( |
| 988 |
! CHECK-SAME: %[[A:.*]]: !fir.ref<!fir.class<!fir.heap<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>> {fir.bindc_name = "a"}, %[[B:.*]]: !fir.ref<!fir.class<!fir.heap<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>> {fir.bindc_name = "b"}) { |
| 989 |
! CHECK: %[[TYPE_DESC:.*]] = fir.type_desc !fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}> |
| 990 |
! CHECK: %[[B_CONV:.*]] = fir.convert %[[B]] : (!fir.ref<!fir.class<!fir.heap<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>>) -> !fir.ref<!fir.box<none>> |
| 991 |
! CHECK: %[[A_CONV:.*]] = fir.convert %[[A]] : (!fir.ref<!fir.class<!fir.heap<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>>) -> !fir.ref<!fir.box<none>> |
| 992 |
! CHECK: %[[TYPE_DESC_CONV:.*]] = fir.convert %[[TYPE_DESC]] : (!fir.tdesc<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>) -> !fir.ref<none> |
| 993 |
! CHECK: %{{.*}} = fir.call @_FortranAMoveAlloc(%[[B_CONV]], %[[A_CONV]], %[[TYPE_DESC_CONV]], %{{.*}}, %{{.*}}, %{{.*}}, %{{.*}}) {{.*}} : (!fir.ref<!fir.box<none>>, !fir.ref<!fir.box<none>>, !fir.ref<none>, i1, !fir.box<none>, !fir.ref<i8>, i32) -> i32 |
| 994 |
|
| 995 |
subroutine test_parent_comp_in_select_type(s) |
| 996 |
class(p1), allocatable :: s |
| 997 |
class(p1), allocatable :: p |
| 998 |
|
| 999 |
allocate(p1::p) |
| 1000 |
|
| 1001 |
select type(s) |
| 1002 |
type is(p2) |
| 1003 |
s%p1 = p |
| 1004 |
end select |
| 1005 |
end subroutine |
| 1006 |
|
| 1007 |
! CHECK-LABEL: func.func @_QMpolymorphic_testPtest_parent_comp_in_select_type( |
| 1008 |
! CHECK-SAME: %[[S:.*]]: !fir.ref<!fir.class<!fir.heap<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>> {fir.bindc_name = "s"}) { |
| 1009 |
! CHECK: %[[P:.*]] = fir.alloca !fir.class<!fir.heap<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>> {bindc_name = "p", uniq_name = "_QMpolymorphic_testFtest_parent_comp_in_select_typeEp"} |
| 1010 |
! CHECK: %[[LOAD_S:.*]] = fir.load %[[S]] : !fir.ref<!fir.class<!fir.heap<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>> |
| 1011 |
! CHECK: fir.select_type %[[LOAD_S]] : !fir.class<!fir.heap<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>> [#fir.type_is<!fir.type<_QMpolymorphic_testTp2{a:i32,b:i32,c:f32}>>, ^bb1, unit, ^bb2] |
| 1012 |
! CHECK: ^bb1: |
| 1013 |
! CHECK: %[[CONV_S:.*]] = fir.convert %[[LOAD_S]] : (!fir.class<!fir.heap<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>) -> !fir.box<!fir.heap<!fir.type<_QMpolymorphic_testTp2{a:i32,b:i32,c:f32}>>> |
| 1014 |
! CHECK: %[[REBOX_P1:.*]] = fir.rebox %[[CONV_S]] : (!fir.box<!fir.heap<!fir.type<_QMpolymorphic_testTp2{a:i32,b:i32,c:f32}>>>) -> !fir.box<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>> |
| 1015 |
! CHECK: %[[LOAD_P:.*]] = fir.load %[[P]] : !fir.ref<!fir.class<!fir.heap<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>> |
| 1016 |
! CHECK: %[[LHS_CONV:.*]] = fir.convert %[[REBOX_P1]] : (!fir.box<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>) -> !fir.ref<!fir.box<none>> |
| 1017 |
! CHECK: %[[RHS_CONV:.*]] = fir.convert %[[LOAD_P]] : (!fir.class<!fir.heap<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>) -> !fir.box<none> |
| 1018 |
! CHECK: %{{.*}} = fir.call @_FortranAAssign(%[[LHS_CONV]], %[[RHS_CONV]], %{{.*}}, %{{.*}}) {{.*}} : (!fir.ref<!fir.box<none>>, !fir.box<none>, !fir.ref<i8>, i32) -> none |
| 1019 |
|
| 1020 |
subroutine move_alloc_unlimited_poly(a, b) |
| 1021 |
class(*), allocatable :: a, b |
| 1022 |
|
| 1023 |
call move_alloc(a, b) |
| 1024 |
end subroutine |
| 1025 |
|
| 1026 |
! CHECK-LABEL: func.func @_QMpolymorphic_testPmove_alloc_unlimited_poly( |
| 1027 |
! CHECK-SAME: %[[A:.*]]: !fir.ref<!fir.class<!fir.heap<none>>> {fir.bindc_name = "a"}, %[[B:.*]]: !fir.ref<!fir.class<!fir.heap<none>>> {fir.bindc_name = "b"}) { |
| 1028 |
! CHECK: %[[NULL:.*]] = fir.zero_bits !fir.ref<none> |
| 1029 |
! CHECK: %[[B_CONV:.*]] = fir.convert %[[B]] : (!fir.ref<!fir.class<!fir.heap<none>>>) -> !fir.ref<!fir.box<none>> |
| 1030 |
! CHECK: %[[A_CONV:.*]] = fir.convert %[[A]] : (!fir.ref<!fir.class<!fir.heap<none>>>) -> !fir.ref<!fir.box<none>> |
| 1031 |
! CHECK: %{{.*}} = fir.call @_FortranAMoveAlloc(%[[B_CONV]], %[[A_CONV]], %[[NULL]], %{{.*}}, %{{.*}}, %{{.*}}, %{{.*}}) {{.*}} : (!fir.ref<!fir.box<none>>, !fir.ref<!fir.box<none>>, !fir.ref<none>, i1, !fir.box<none>, !fir.ref<i8>, i32) -> i32 |
| 1032 |
|
| 1033 |
subroutine test_parent_comp_intrinsic(a, b) |
| 1034 |
class(p1) :: a |
| 1035 |
type(p2), allocatable :: b |
| 1036 |
logical :: c |
| 1037 |
|
| 1038 |
c = same_type_as(a, b%p1) |
| 1039 |
end subroutine |
| 1040 |
|
| 1041 |
! CHECK-LABEL: func.func @_QMpolymorphic_testPtest_parent_comp_intrinsic( |
| 1042 |
! CHECK-SAME: %[[ARG0:.*]]: !fir.class<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>> {fir.bindc_name = "a"}, %[[ARG1:.*]]: !fir.ref<!fir.box<!fir.heap<!fir.type<_QMpolymorphic_testTp2{a:i32,b:i32,c:f32}>>>> {fir.bindc_name = "b"}) { |
| 1043 |
! CHECK: %[[LOAD_ARG1:.*]] = fir.load %[[ARG1]] : !fir.ref<!fir.box<!fir.heap<!fir.type<_QMpolymorphic_testTp2{a:i32,b:i32,c:f32}>>>> |
| 1044 |
! CHECK: %[[REBOX_ARG1:.*]] = fir.rebox %[[LOAD_ARG1]] : (!fir.box<!fir.heap<!fir.type<_QMpolymorphic_testTp2{a:i32,b:i32,c:f32}>>>) -> !fir.box<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>> |
| 1045 |
! CHECK: %[[BOX_NONE_ARG0:.*]] = fir.convert %[[ARG0]] : (!fir.class<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>) -> !fir.box<none> |
| 1046 |
! CHECK: %[[BOX_NONE_ARG1:.*]] = fir.convert %[[REBOX_ARG1]] : (!fir.box<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>) -> !fir.box<none> |
| 1047 |
! CHECK: %{{.*}} = fir.call @_FortranASameTypeAs(%[[BOX_NONE_ARG0]], %[[BOX_NONE_ARG1]]) {{.*}} : (!fir.box<none>, !fir.box<none>) -> i1 |
| 1048 |
|
| 1049 |
subroutine test_parent_comp_normal(a) |
| 1050 |
class(p2) :: a |
| 1051 |
|
| 1052 |
call print(a%p1) |
| 1053 |
end subroutine |
| 1054 |
|
| 1055 |
! CHECK-LABEL: func.func @_QMpolymorphic_testPtest_parent_comp_normal( |
| 1056 |
! CHECK-SAME: %[[ARG0:.*]]: !fir.class<!fir.type<_QMpolymorphic_testTp2{a:i32,b:i32,c:f32}>> {fir.bindc_name = "a"}) { |
| 1057 |
! CHECK: %[[REBOX:.*]] = fir.rebox %[[ARG0]] : (!fir.class<!fir.type<_QMpolymorphic_testTp2{a:i32,b:i32,c:f32}>>) -> !fir.box<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>> |
| 1058 |
! CHECK: %[[CONV:.*]] = fir.convert %[[REBOX]] : (!fir.box<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>) -> !fir.class<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>> |
| 1059 |
! CHECK: fir.call @_QMpolymorphic_testPprint(%[[CONV]]) {{.*}} : (!fir.class<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>) -> () |
| 1060 |
|
| 1061 |
subroutine takes_p1_opt(a) |
| 1062 |
class(p1), optional :: a |
| 1063 |
end subroutine |
| 1064 |
|
| 1065 |
subroutine test_parent_comp_opt(p) |
| 1066 |
type(p2), allocatable :: p |
| 1067 |
allocate(p) |
| 1068 |
call takes_p1_opt(p%p1) |
| 1069 |
end subroutine |
| 1070 |
|
| 1071 |
! CHECK-LABEL: func.func @_QMpolymorphic_testPtest_parent_comp_opt( |
| 1072 |
! CHECK-SAME: %[[ARG0:.*]]: !fir.ref<!fir.box<!fir.heap<!fir.type<_QMpolymorphic_testTp2{a:i32,b:i32,c:f32}>>>> {fir.bindc_name = "p"}) { |
| 1073 |
! CHECK: %[[LOAD_ARG0:.*]] = fir.load %[[ARG0]] : !fir.ref<!fir.box<!fir.heap<!fir.type<_QMpolymorphic_testTp2{a:i32,b:i32,c:f32}>>>> |
| 1074 |
! CHECK: %[[RES:.*]] = fir.if %{{.*}} -> (!fir.box<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>) { |
| 1075 |
! CHECK: %[[REBOX:.*]] = fir.rebox %[[LOAD_ARG0:.*]] : (!fir.box<!fir.heap<!fir.type<_QMpolymorphic_testTp2{a:i32,b:i32,c:f32}>>>) -> !fir.box<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>> |
| 1076 |
! CHECK: fir.result %[[REBOX]] : !fir.box<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>> |
| 1077 |
! CHECK: %[[CONV:.*]] = fir.convert %[[RES]] : (!fir.box<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>) -> !fir.class<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>> |
| 1078 |
! CHECK: fir.call @_QMpolymorphic_testPtakes_p1_opt(%[[CONV]]) {{.*}} : (!fir.class<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>) -> () |
| 1079 |
|
| 1080 |
subroutine class_with_entry(a) |
| 1081 |
class(p1) :: a,b |
| 1082 |
select type (a) |
| 1083 |
type is(p2) |
| 1084 |
print*, a%c |
| 1085 |
class default |
| 1086 |
print*, a%a |
| 1087 |
end select |
| 1088 |
return |
| 1089 |
entry d(b) |
| 1090 |
select type(b) |
| 1091 |
type is(p2) |
| 1092 |
print*,b%c |
| 1093 |
class default |
| 1094 |
print*,b%a |
| 1095 |
end select |
| 1096 |
end subroutine |
| 1097 |
|
| 1098 |
! CHECK-LABEL: func.func @_QMpolymorphic_testPclass_with_entry( |
| 1099 |
! CHECK-SAME: %[[A:.*]]: !fir.class<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>> {fir.bindc_name = "a"}) { |
| 1100 |
! CHECK: %[[B:.*]] = fir.alloca !fir.class<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>> {bindc_name = "b", uniq_name = "_QMpolymorphic_testFclass_with_entryEb"} |
| 1101 |
|
| 1102 |
! CHECK-LABEL: func.func @_QMpolymorphic_testPd( |
| 1103 |
! CHECK-SAME: %[[B:.*]]: !fir.class<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>> {fir.bindc_name = "b"}) { |
| 1104 |
! CHECK: %[[A:.*]] = fir.alloca !fir.class<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>> {bindc_name = "a", uniq_name = "_QMpolymorphic_testFclass_with_entryEa"} |
| 1105 |
|
| 1106 |
subroutine class_array_with_entry(a) |
| 1107 |
class(p1) :: a(:), b(:) |
| 1108 |
select type (a) |
| 1109 |
type is(p2) |
| 1110 |
print*, a%c |
| 1111 |
class default |
| 1112 |
print*, a%a |
| 1113 |
end select |
| 1114 |
return |
| 1115 |
entry g(b) |
| 1116 |
select type(b) |
| 1117 |
type is(p2) |
| 1118 |
print*,b%c |
| 1119 |
class default |
| 1120 |
print*,b%a |
| 1121 |
end select |
| 1122 |
end subroutine |
| 1123 |
|
| 1124 |
! CHECK-LABEL: func.func @_QMpolymorphic_testPclass_array_with_entry( |
| 1125 |
! CHECK-SAME: %[[A:.*]]: !fir.class<!fir.array<?x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>> {fir.bindc_name = "a"}) { |
| 1126 |
! CHECK: %[[B:.*]] = fir.alloca !fir.class<!fir.heap<!fir.array<?x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>> |
| 1127 |
|
| 1128 |
! CHECK-LABEL: func.func @_QMpolymorphic_testPg( |
| 1129 |
! CHECK-SAME: %[[B:.*]]: !fir.class<!fir.array<?x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>> {fir.bindc_name = "b"}) { |
| 1130 |
! CHECK: %[[A:.*]] = fir.alloca !fir.class<!fir.heap<!fir.array<?x!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>>> |
| 1131 |
|
| 1132 |
subroutine pass_up(up) |
| 1133 |
class(*), intent(in) :: up |
| 1134 |
end subroutine |
| 1135 |
|
| 1136 |
! TODO: unlimited polymorphic temporary in lowering |
| 1137 |
! subroutine parenthesized_up(a) |
| 1138 |
! type(p5) :: a |
| 1139 |
! call pass_up((a%up)) |
| 1140 |
! end subroutine |
| 1141 |
|
| 1142 |
end module |
| 1143 |
|
| 1144 |
program test |
| 1145 |
use polymorphic_test |
| 1146 |
type(outer), allocatable :: o |
| 1147 |
integer :: i(5) |
| 1148 |
logical :: l(5) |
| 1149 |
allocate(o) |
| 1150 |
|
| 1151 |
l = i < o%inner |
| 1152 |
end program |
| 1153 |
|
| 1154 |
! CHECK-LABEL: func.func @_QQmain() attributes {fir.bindc_name = "test"} { |
| 1155 |
! CHECK: %[[ADDR_O:.*]] = fir.address_of(@_QFEo) : !fir.ref<!fir.box<!fir.heap<!fir.type<_QMpolymorphic_testTouter{inner:!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>}>>>> |
| 1156 |
! CHECK: %[[BOX_NONE:.*]] = fir.convert %[[ADDR_O]] : (!fir.ref<!fir.box<!fir.heap<!fir.type<_QMpolymorphic_testTouter{inner:!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>}>>>>) -> !fir.ref<!fir.box<none>> |
| 1157 |
! CHECK: %{{.*}} = fir.call @_FortranAAllocatableAllocate(%[[BOX_NONE]], %{{.*}}, %{{.*}}, %{{.*}}, %{{.*}}) {{.*}} : (!fir.ref<!fir.box<none>>, i1, !fir.box<none>, !fir.ref<i8>, i32) -> i32 |
| 1158 |
! CHECK: %[[O:.*]] = fir.load %[[ADDR_O]] : !fir.ref<!fir.box<!fir.heap<!fir.type<_QMpolymorphic_testTouter{inner:!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>}>>>> |
| 1159 |
! CHECK: %[[FIELD_INNER:.*]] = fir.field_index inner, !fir.type<_QMpolymorphic_testTouter{inner:!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>}> |
| 1160 |
! CHECK: %[[COORD_INNER:.*]] = fir.coordinate_of %[[O]], %[[FIELD_INNER]] : (!fir.box<!fir.heap<!fir.type<_QMpolymorphic_testTouter{inner:!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>}>>>, !fir.field) -> !fir.ref<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>> |
| 1161 |
! CHECK: %{{.*}} = fir.do_loop %{{.*}} = %{{.*}} to %{{.*}} step %{{.*}} unordered iter_args(%arg1 = %9) -> (!fir.array<5x!fir.logical<4>>) { |
| 1162 |
! CHECK: %[[EMBOXED:.*]] = fir.embox %[[COORD_INNER]] : (!fir.ref<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>) -> !fir.class<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>> |
| 1163 |
! CHECK: %{{.*}} = fir.call @_QMpolymorphic_testPlt(%17, %[[EMBOXED]]) {{.*}} : (!fir.ref<i32>, !fir.class<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>) -> !fir.logical<4> |
| 1164 |
! CHECK: } |