Debian Codegraph @

flang/test/Lower/HLFIR/elemental-user-procedure-ref-polymorphic.f90

raw
1 ! Test lowering of user defined elemental procedure reference to HLFIR
2 ! With polymorphic arguments.
3 ! RUN: bbc -emit-hlfir -I nw -o - %s 2>&1 | FileCheck %s
4 module def_some_types
5 type :: t
6 integer :: i
7 end type
8 end module
9
10 subroutine test_polymporphic_array(scalar)
11 use def_some_types
12 interface
13 function return_array_with_side_effects()
14 import :: t
15 class(t), pointer :: return_array_with_side_effects(:)
16 end function
17 integer elemental function elem(lhs, rhs)
18 import :: t
19 class(t), intent(in) :: lhs, rhs
20 end function elem
21 end interface
22 class(t) :: scalar
23 call bar(elem(scalar, return_array_with_side_effects()))
24 contains
25 end
26
27 ! CHECK-LABEL: func.func @_QPtest_polymporphic_array(
28 ! CHECK: %[[VAL_1:.*]] = fir.alloca !fir.class<!fir.ptr<!fir.array<?x!fir.type<_QMdef_some_typesTt{i:i32}>>>> {bindc_name = ".result"}
29 ! CHECK: %[[VAL_2:.*]]:2 = hlfir.declare {{.*}}scalar
30 ! CHECK: %[[VAL_3:.*]] = fir.call @_QPreturn_array_with_side_effects() {{.*}}: () -> !fir.class<!fir.ptr<!fir.array<?x!fir.type<_QMdef_some_typesTt{i:i32}>>>>
31 ! CHECK: fir.save_result %[[VAL_3]] to %[[VAL_1:.*]] : !fir.class<!fir.ptr<!fir.array<?x!fir.type<_QMdef_some_typesTt{i:i32}>>>>, !fir.ref<!fir.class<!fir.ptr<!fir.array<?x!fir.type<_QMdef_some_typesTt{i:i32}>>>>>
32 ! CHECK: %[[VAL_4:.*]]:2 = hlfir.declare %[[VAL_1]] {uniq_name = ".tmp.func_result"} : (!fir.ref<!fir.class<!fir.ptr<!fir.array<?x!fir.type<_QMdef_some_typesTt{i:i32}>>>>>) -> (!fir.ref<!fir.class<!fir.ptr<!fir.array<?x!fir.type<_QMdef_some_typesTt{i:i32}>>>>>, !fir.ref<!fir.class<!fir.ptr<!fir.array<?x!fir.type<_QMdef_some_typesTt{i:i32}>>>>>)
33 ! CHECK: %[[VAL_5:.*]] = fir.load %[[VAL_4]]#0 : !fir.ref<!fir.class<!fir.ptr<!fir.array<?x!fir.type<_QMdef_some_typesTt{i:i32}>>>>>
34 ! CHECK: %[[VAL_6:.*]] = arith.constant 0 : index
35 ! CHECK: %[[VAL_7:.*]]:3 = fir.box_dims %[[VAL_5]], %[[VAL_6]] : (!fir.class<!fir.ptr<!fir.array<?x!fir.type<_QMdef_some_typesTt{i:i32}>>>>, index) -> (index, index, index)
36 ! CHECK: %[[VAL_8:.*]] = fir.shape %[[VAL_7]]#1 : (index) -> !fir.shape<1>
37 ! CHECK: %[[VAL_9:.*]] = hlfir.elemental %[[VAL_8]] unordered : (!fir.shape<1>) -> !hlfir.expr<?xi32> {
38 ! CHECK: ^bb0(%[[VAL_10:.*]]: index):
39 ! CHECK: %[[VAL_11:.*]] = arith.constant 0 : index
40 ! CHECK: %[[VAL_12:.*]]:3 = fir.box_dims %[[VAL_5]], %[[VAL_11]] : (!fir.class<!fir.ptr<!fir.array<?x!fir.type<_QMdef_some_typesTt{i:i32}>>>>, index) -> (index, index, index)
41 ! CHECK: %[[VAL_13:.*]] = arith.constant 1 : index
42 ! CHECK: %[[VAL_14:.*]] = arith.subi %[[VAL_12]]#0, %[[VAL_13]] : index
43 ! CHECK: %[[VAL_15:.*]] = arith.addi %[[VAL_10]], %[[VAL_14]] : index
44 ! CHECK: %[[VAL_16:.*]] = hlfir.designate %[[VAL_5]] (%[[VAL_15]]) : (!fir.class<!fir.ptr<!fir.array<?x!fir.type<_QMdef_some_typesTt{i:i32}>>>>, index) -> !fir.class<!fir.type<_QMdef_some_typesTt{i:i32}>>
45 ! CHECK: %[[VAL_17:.*]] = fir.call @_QPelem(%[[VAL_2]]#0, %[[VAL_16]]) {{.*}}: (!fir.class<!fir.type<_QMdef_some_typesTt{i:i32}>>, !fir.class<!fir.type<_QMdef_some_typesTt{i:i32}>>) -> i32
46 ! CHECK: hlfir.yield_element %[[VAL_17]] : i32
47 ! CHECK: }
48 ! CHECK: %[[VAL_18:.*]]:3 = hlfir.associate %[[VAL_9]](%[[VAL_8]]) {adapt.valuebyref} : (!hlfir.expr<?xi32>, !fir.shape<1>) -> (!fir.box<!fir.array<?xi32>>, !fir.ref<!fir.array<?xi32>>, i1)
49 ! CHECK: fir.call @_QPbar(%[[VAL_18]]#1) {{.*}}: (!fir.ref<!fir.array<?xi32>>) -> ()