| 1 |
! Test lowering of user defined assignment to HLFIR |
| 2 |
! RUN: bbc -emit-hlfir -o - %s 2>&1 | FileCheck %s |
| 3 |
|
| 4 |
module user_def |
| 5 |
interface assignment ( = ) |
| 6 |
elemental pure subroutine logical_to_numeric(i, l) |
| 7 |
integer, intent (out) :: i |
| 8 |
logical, intent (in) :: l |
| 9 |
end subroutine |
| 10 |
elemental pure subroutine logical_to_complex(z, l) |
| 11 |
complex, intent (out) :: z |
| 12 |
logical, value :: l |
| 13 |
end subroutine |
| 14 |
pure subroutine logical_array_to_real(x, l) |
| 15 |
real, intent (out) :: x(:) |
| 16 |
logical, intent (in) :: l(:) |
| 17 |
end subroutine |
| 18 |
subroutine real_to_int_pointer(p, x) |
| 19 |
integer, pointer, intent(out) :: p(:) |
| 20 |
real, intent(in) :: x(:, :) |
| 21 |
end subroutine |
| 22 |
subroutine real_to_int_allocatable(p, x) |
| 23 |
integer, allocatable, intent(out) :: p(:, :) |
| 24 |
real, intent(in) :: x(:) |
| 25 |
end subroutine |
| 26 |
end interface |
| 27 |
|
| 28 |
contains |
| 29 |
|
| 30 |
subroutine test_user_defined_elemental_array(i, l) |
| 31 |
integer :: i(:) |
| 32 |
logical :: l(:) |
| 33 |
i = l |
| 34 |
end subroutine |
| 35 |
! CHECK-LABEL: func.func @_QMuser_defPtest_user_defined_elemental_array( |
| 36 |
! CHECK-SAME: %[[VAL_0:.*]]: !fir.box<!fir.array<?xi32>> {fir.bindc_name = "i"}, |
| 37 |
! CHECK-SAME: %[[VAL_1:.*]]: !fir.box<!fir.array<?x!fir.logical<4>>> {fir.bindc_name = "l"}) { |
| 38 |
! CHECK: %[[VAL_2:.*]]:2 = hlfir.declare %[[VAL_0]] dummy_scope %{{[0-9]+}} {uniq_name = "_QMuser_defFtest_user_defined_elemental_arrayEi"} : (!fir.box<!fir.array<?xi32>>, !fir.dscope) -> (!fir.box<!fir.array<?xi32>>, !fir.box<!fir.array<?xi32>>) |
| 39 |
! CHECK: %[[VAL_3:.*]]:2 = hlfir.declare %[[VAL_1]] dummy_scope %{{[0-9]+}} {uniq_name = "_QMuser_defFtest_user_defined_elemental_arrayEl"} : (!fir.box<!fir.array<?x!fir.logical<4>>>, !fir.dscope) -> (!fir.box<!fir.array<?x!fir.logical<4>>>, !fir.box<!fir.array<?x!fir.logical<4>>>) |
| 40 |
! CHECK: hlfir.region_assign { |
| 41 |
! CHECK: hlfir.yield %[[VAL_3]]#0 : !fir.box<!fir.array<?x!fir.logical<4>>> |
| 42 |
! CHECK: } to { |
| 43 |
! CHECK: hlfir.yield %[[VAL_2]]#0 : !fir.box<!fir.array<?xi32>> |
| 44 |
! CHECK: } user_defined_assign (%[[VAL_4:.*]]: !fir.ref<!fir.logical<4>>) to (%[[VAL_5:.*]]: !fir.ref<i32>) { |
| 45 |
! CHECK: fir.call @_QPlogical_to_numeric(%[[VAL_5]], %[[VAL_4]]) {{.*}}: (!fir.ref<i32>, !fir.ref<!fir.logical<4>>) -> () |
| 46 |
! CHECK: } |
| 47 |
|
| 48 |
subroutine test_user_defined_elemental_array_value(z, l) |
| 49 |
logical :: l(:) |
| 50 |
complex :: z(:) |
| 51 |
z = l |
| 52 |
end subroutine |
| 53 |
! CHECK-LABEL: func.func @_QMuser_defPtest_user_defined_elemental_array_value( |
| 54 |
! CHECK-SAME: %[[VAL_0:.*]]: !fir.box<!fir.array<?x!fir.complex<4>>> {fir.bindc_name = "z"}, |
| 55 |
! CHECK-SAME: %[[VAL_1:.*]]: !fir.box<!fir.array<?x!fir.logical<4>>> {fir.bindc_name = "l"}) { |
| 56 |
! CHECK: %[[VAL_2:.*]]:2 = hlfir.declare %[[VAL_1]] dummy_scope %{{[0-9]+}} {uniq_name = "_QMuser_defFtest_user_defined_elemental_array_valueEl"} : (!fir.box<!fir.array<?x!fir.logical<4>>>, !fir.dscope) -> (!fir.box<!fir.array<?x!fir.logical<4>>>, !fir.box<!fir.array<?x!fir.logical<4>>>) |
| 57 |
! CHECK: %[[VAL_3:.*]]:2 = hlfir.declare %[[VAL_0]] dummy_scope %{{[0-9]+}} {uniq_name = "_QMuser_defFtest_user_defined_elemental_array_valueEz"} : (!fir.box<!fir.array<?x!fir.complex<4>>>, !fir.dscope) -> (!fir.box<!fir.array<?x!fir.complex<4>>>, !fir.box<!fir.array<?x!fir.complex<4>>>) |
| 58 |
! CHECK: hlfir.region_assign { |
| 59 |
! CHECK: hlfir.yield %[[VAL_2]]#0 : !fir.box<!fir.array<?x!fir.logical<4>>> |
| 60 |
! CHECK: } to { |
| 61 |
! CHECK: hlfir.yield %[[VAL_3]]#0 : !fir.box<!fir.array<?x!fir.complex<4>>> |
| 62 |
! CHECK: } user_defined_assign (%[[VAL_4:.*]]: !fir.ref<!fir.logical<4>>) to (%[[VAL_5:.*]]: !fir.ref<!fir.complex<4>>) { |
| 63 |
! CHECK: %[[VAL_6:.*]] = fir.load %[[VAL_4]] : !fir.ref<!fir.logical<4>> |
| 64 |
! CHECK: fir.call @_QPlogical_to_complex(%[[VAL_5]], %[[VAL_6]]) {{.*}}: (!fir.ref<!fir.complex<4>>, !fir.logical<4>) -> () |
| 65 |
! CHECK: } |
| 66 |
|
| 67 |
subroutine test_user_defined_scalar(i, l) |
| 68 |
integer :: i |
| 69 |
logical :: l |
| 70 |
i = l |
| 71 |
end subroutine |
| 72 |
! CHECK-LABEL: func.func @_QMuser_defPtest_user_defined_scalar( |
| 73 |
! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<i32> {fir.bindc_name = "i"}, |
| 74 |
! CHECK-SAME: %[[VAL_1:.*]]: !fir.ref<!fir.logical<4>> {fir.bindc_name = "l"}) { |
| 75 |
! CHECK: %[[VAL_2:.*]]:2 = hlfir.declare %[[VAL_0]] dummy_scope %{{[0-9]+}} {uniq_name = "_QMuser_defFtest_user_defined_scalarEi"} : (!fir.ref<i32>, !fir.dscope) -> (!fir.ref<i32>, !fir.ref<i32>) |
| 76 |
! CHECK: %[[VAL_3:.*]]:2 = hlfir.declare %[[VAL_1]] dummy_scope %{{[0-9]+}} {uniq_name = "_QMuser_defFtest_user_defined_scalarEl"} : (!fir.ref<!fir.logical<4>>, !fir.dscope) -> (!fir.ref<!fir.logical<4>>, !fir.ref<!fir.logical<4>>) |
| 77 |
! CHECK: hlfir.region_assign { |
| 78 |
! CHECK: %[[VAL_4:.*]] = fir.load %[[VAL_3]]#0 : !fir.ref<!fir.logical<4>> |
| 79 |
! CHECK: hlfir.yield %[[VAL_4]] : !fir.logical<4> |
| 80 |
! CHECK: } to { |
| 81 |
! CHECK: hlfir.yield %[[VAL_2]]#0 : !fir.ref<i32> |
| 82 |
! CHECK: } user_defined_assign (%[[VAL_5:.*]]: !fir.logical<4>) to (%[[VAL_6:.*]]: !fir.ref<i32>) { |
| 83 |
! CHECK: %[[VAL_7:.*]]:3 = hlfir.associate %[[VAL_5]] {adapt.valuebyref} : (!fir.logical<4>) -> (!fir.ref<!fir.logical<4>>, !fir.ref<!fir.logical<4>>, i1) |
| 84 |
! CHECK: fir.call @_QPlogical_to_numeric(%[[VAL_6]], %[[VAL_7]]#1) {{.*}}: (!fir.ref<i32>, !fir.ref<!fir.logical<4>>) -> () |
| 85 |
! CHECK: hlfir.end_associate %[[VAL_7]]#1, %[[VAL_7]]#2 : !fir.ref<!fir.logical<4>>, i1 |
| 86 |
! CHECK: } |
| 87 |
|
| 88 |
subroutine test_non_elemental_array(x) |
| 89 |
real :: x(:) |
| 90 |
x = x.lt.42 |
| 91 |
end subroutine |
| 92 |
! CHECK-LABEL: func.func @_QMuser_defPtest_non_elemental_array( |
| 93 |
! CHECK-SAME: %[[VAL_0:.*]]: !fir.box<!fir.array<?xf32>> {fir.bindc_name = "x"}) { |
| 94 |
! CHECK: %[[VAL_1:.*]]:2 = hlfir.declare %[[VAL_0]] dummy_scope %{{[0-9]+}} {uniq_name = "_QMuser_defFtest_non_elemental_arrayEx"} : (!fir.box<!fir.array<?xf32>>, !fir.dscope) -> (!fir.box<!fir.array<?xf32>>, !fir.box<!fir.array<?xf32>>) |
| 95 |
! CHECK: hlfir.region_assign { |
| 96 |
! CHECK: %[[VAL_2:.*]] = arith.constant 4.200000e+01 : f32 |
| 97 |
! CHECK: %[[VAL_3:.*]] = arith.constant 0 : index |
| 98 |
! CHECK: %[[VAL_4:.*]]:3 = fir.box_dims %[[VAL_1]]#0, %[[VAL_3]] : (!fir.box<!fir.array<?xf32>>, index) -> (index, index, index) |
| 99 |
! CHECK: %[[VAL_5:.*]] = fir.shape %[[VAL_4]]#1 : (index) -> !fir.shape<1> |
| 100 |
! CHECK: %[[VAL_6:.*]] = hlfir.elemental %[[VAL_5]] unordered : (!fir.shape<1>) -> !hlfir.expr<?x!fir.logical<4>> { |
| 101 |
! CHECK: ^bb0(%[[VAL_7:.*]]: index): |
| 102 |
! CHECK: %[[VAL_8:.*]] = hlfir.designate %[[VAL_1]]#0 (%[[VAL_7]]) : (!fir.box<!fir.array<?xf32>>, index) -> !fir.ref<f32> |
| 103 |
! CHECK: %[[VAL_9:.*]] = fir.load %[[VAL_8]] : !fir.ref<f32> |
| 104 |
! CHECK: %[[VAL_10:.*]] = arith.cmpf olt, %[[VAL_9]], %[[VAL_2]] {{.*}} : f32 |
| 105 |
! CHECK: %[[VAL_11:.*]] = fir.convert %[[VAL_10]] : (i1) -> !fir.logical<4> |
| 106 |
! CHECK: hlfir.yield_element %[[VAL_11]] : !fir.logical<4> |
| 107 |
! CHECK: } |
| 108 |
! CHECK: hlfir.yield %[[VAL_12:.*]] : !hlfir.expr<?x!fir.logical<4>> cleanup { |
| 109 |
! CHECK: hlfir.destroy %[[VAL_12]] : !hlfir.expr<?x!fir.logical<4>> |
| 110 |
! CHECK: } |
| 111 |
! CHECK: } to { |
| 112 |
! CHECK: hlfir.yield %[[VAL_1]]#0 : !fir.box<!fir.array<?xf32>> |
| 113 |
! CHECK: } user_defined_assign (%[[VAL_13:.*]]: !hlfir.expr<?x!fir.logical<4>>) to (%[[VAL_14:.*]]: !fir.box<!fir.array<?xf32>>) { |
| 114 |
! CHECK: %[[VAL_15:.*]] = hlfir.shape_of %[[VAL_13]] : (!hlfir.expr<?x!fir.logical<4>>) -> !fir.shape<1> |
| 115 |
! CHECK: %[[VAL_16:.*]]:3 = hlfir.associate %[[VAL_13]](%[[VAL_15]]) {adapt.valuebyref} : (!hlfir.expr<?x!fir.logical<4>>, !fir.shape<1>) -> (!fir.box<!fir.array<?x!fir.logical<4>>>, !fir.ref<!fir.array<?x!fir.logical<4>>>, i1) |
| 116 |
! CHECK: fir.call @_QPlogical_array_to_real(%[[VAL_14]], %[[VAL_16]]#0) {{.*}}: (!fir.box<!fir.array<?xf32>>, !fir.box<!fir.array<?x!fir.logical<4>>>) -> () |
| 117 |
! CHECK: hlfir.end_associate %[[VAL_16]]#1, %[[VAL_16]]#2 : !fir.ref<!fir.array<?x!fir.logical<4>>>, i1 |
| 118 |
! CHECK: } |
| 119 |
|
| 120 |
subroutine test_where_user_def_assignment(i, l, l2) |
| 121 |
integer :: i(:) |
| 122 |
logical :: l(:), l2(:) |
| 123 |
where (l) i = l.neqv.l2 |
| 124 |
end subroutine |
| 125 |
! CHECK-LABEL: func.func @_QMuser_defPtest_where_user_def_assignment( |
| 126 |
! CHECK-SAME: %[[VAL_0:.*]]: !fir.box<!fir.array<?xi32>> {fir.bindc_name = "i"}, |
| 127 |
! CHECK-SAME: %[[VAL_1:.*]]: !fir.box<!fir.array<?x!fir.logical<4>>> {fir.bindc_name = "l"}, |
| 128 |
! CHECK-SAME: %[[VAL_2:.*]]: !fir.box<!fir.array<?x!fir.logical<4>>> {fir.bindc_name = "l2"}) { |
| 129 |
! CHECK: %[[VAL_3:.*]]:2 = hlfir.declare %[[VAL_0]] dummy_scope %{{[0-9]+}} {uniq_name = "_QMuser_defFtest_where_user_def_assignmentEi"} : (!fir.box<!fir.array<?xi32>>, !fir.dscope) -> (!fir.box<!fir.array<?xi32>>, !fir.box<!fir.array<?xi32>>) |
| 130 |
! CHECK: %[[VAL_4:.*]]:2 = hlfir.declare %[[VAL_1]] dummy_scope %{{[0-9]+}} {uniq_name = "_QMuser_defFtest_where_user_def_assignmentEl"} : (!fir.box<!fir.array<?x!fir.logical<4>>>, !fir.dscope) -> (!fir.box<!fir.array<?x!fir.logical<4>>>, !fir.box<!fir.array<?x!fir.logical<4>>>) |
| 131 |
! CHECK: %[[VAL_5:.*]]:2 = hlfir.declare %[[VAL_2]] dummy_scope %{{[0-9]+}} {uniq_name = "_QMuser_defFtest_where_user_def_assignmentEl2"} : (!fir.box<!fir.array<?x!fir.logical<4>>>, !fir.dscope) -> (!fir.box<!fir.array<?x!fir.logical<4>>>, !fir.box<!fir.array<?x!fir.logical<4>>>) |
| 132 |
! CHECK: hlfir.where { |
| 133 |
! CHECK: hlfir.yield %[[VAL_4]]#0 : !fir.box<!fir.array<?x!fir.logical<4>>> |
| 134 |
! CHECK: } do { |
| 135 |
! CHECK: hlfir.region_assign { |
| 136 |
! CHECK: %[[VAL_6:.*]] = arith.constant 0 : index |
| 137 |
! CHECK: %[[VAL_7:.*]]:3 = fir.box_dims %[[VAL_4]]#0, %[[VAL_6]] : (!fir.box<!fir.array<?x!fir.logical<4>>>, index) -> (index, index, index) |
| 138 |
! CHECK: %[[VAL_8:.*]] = fir.shape %[[VAL_7]]#1 : (index) -> !fir.shape<1> |
| 139 |
! CHECK: %[[VAL_9:.*]] = hlfir.elemental %[[VAL_8]] unordered : (!fir.shape<1>) -> !hlfir.expr<?x!fir.logical<4>> { |
| 140 |
! CHECK: ^bb0(%[[VAL_10:.*]]: index): |
| 141 |
! CHECK: %[[VAL_11:.*]] = hlfir.designate %[[VAL_4]]#0 (%[[VAL_10]]) : (!fir.box<!fir.array<?x!fir.logical<4>>>, index) -> !fir.ref<!fir.logical<4>> |
| 142 |
! CHECK: %[[VAL_12:.*]] = hlfir.designate %[[VAL_5]]#0 (%[[VAL_10]]) : (!fir.box<!fir.array<?x!fir.logical<4>>>, index) -> !fir.ref<!fir.logical<4>> |
| 143 |
! CHECK: %[[VAL_13:.*]] = fir.load %[[VAL_11]] : !fir.ref<!fir.logical<4>> |
| 144 |
! CHECK: %[[VAL_14:.*]] = fir.load %[[VAL_12]] : !fir.ref<!fir.logical<4>> |
| 145 |
! CHECK: %[[VAL_15:.*]] = fir.convert %[[VAL_13]] : (!fir.logical<4>) -> i1 |
| 146 |
! CHECK: %[[VAL_16:.*]] = fir.convert %[[VAL_14]] : (!fir.logical<4>) -> i1 |
| 147 |
! CHECK: %[[VAL_17:.*]] = arith.cmpi ne, %[[VAL_15]], %[[VAL_16]] : i1 |
| 148 |
! CHECK: %[[VAL_18:.*]] = fir.convert %[[VAL_17]] : (i1) -> !fir.logical<4> |
| 149 |
! CHECK: hlfir.yield_element %[[VAL_18]] : !fir.logical<4> |
| 150 |
! CHECK: } |
| 151 |
! CHECK: hlfir.yield %[[VAL_19:.*]] : !hlfir.expr<?x!fir.logical<4>> cleanup { |
| 152 |
! CHECK: hlfir.destroy %[[VAL_19]] : !hlfir.expr<?x!fir.logical<4>> |
| 153 |
! CHECK: } |
| 154 |
! CHECK: } to { |
| 155 |
! CHECK: hlfir.yield %[[VAL_3]]#0 : !fir.box<!fir.array<?xi32>> |
| 156 |
! CHECK: } user_defined_assign (%[[VAL_20:.*]]: !fir.logical<4>) to (%[[VAL_21:.*]]: !fir.ref<i32>) { |
| 157 |
! CHECK: %[[VAL_22:.*]]:3 = hlfir.associate %[[VAL_20]] {adapt.valuebyref} : (!fir.logical<4>) -> (!fir.ref<!fir.logical<4>>, !fir.ref<!fir.logical<4>>, i1) |
| 158 |
! CHECK: fir.call @_QPlogical_to_numeric(%[[VAL_21]], %[[VAL_22]]#1) {{.*}}: (!fir.ref<i32>, !fir.ref<!fir.logical<4>>) -> () |
| 159 |
! CHECK: hlfir.end_associate %[[VAL_22]]#1, %[[VAL_22]]#2 : !fir.ref<!fir.logical<4>>, i1 |
| 160 |
! CHECK: } |
| 161 |
! CHECK: } |
| 162 |
|
| 163 |
subroutine test_forall_user_def_assignment(i, l) |
| 164 |
integer :: i(20, 10) |
| 165 |
logical :: l(20, 10) |
| 166 |
forall (j=1:10) i(:, j) = l(:, j) |
| 167 |
end subroutine |
| 168 |
! CHECK-LABEL: func.func @_QMuser_defPtest_forall_user_def_assignment( |
| 169 |
! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<!fir.array<20x10xi32>> {fir.bindc_name = "i"}, |
| 170 |
! CHECK-SAME: %[[VAL_1:.*]]: !fir.ref<!fir.array<20x10x!fir.logical<4>>> {fir.bindc_name = "l"}) { |
| 171 |
! CHECK: %[[VAL_2:.*]] = arith.constant 20 : index |
| 172 |
! CHECK: %[[VAL_3:.*]] = arith.constant 10 : index |
| 173 |
! CHECK: %[[VAL_4:.*]] = fir.shape %[[VAL_2]], %[[VAL_3]] : (index, index) -> !fir.shape<2> |
| 174 |
! CHECK: %[[VAL_5:.*]]:2 = hlfir.declare %[[VAL_0]](%[[VAL_4]]) dummy_scope %{{[0-9]+}} {uniq_name = "_QMuser_defFtest_forall_user_def_assignmentEi"} : (!fir.ref<!fir.array<20x10xi32>>, !fir.shape<2>, !fir.dscope) -> (!fir.ref<!fir.array<20x10xi32>>, !fir.ref<!fir.array<20x10xi32>>) |
| 175 |
! CHECK: %[[VAL_6:.*]] = arith.constant 20 : index |
| 176 |
! CHECK: %[[VAL_7:.*]] = arith.constant 10 : index |
| 177 |
! CHECK: %[[VAL_8:.*]] = fir.shape %[[VAL_6]], %[[VAL_7]] : (index, index) -> !fir.shape<2> |
| 178 |
! CHECK: %[[VAL_9:.*]]:2 = hlfir.declare %[[VAL_1]](%[[VAL_8]]) dummy_scope %{{[0-9]+}} {uniq_name = "_QMuser_defFtest_forall_user_def_assignmentEl"} : (!fir.ref<!fir.array<20x10x!fir.logical<4>>>, !fir.shape<2>, !fir.dscope) -> (!fir.ref<!fir.array<20x10x!fir.logical<4>>>, !fir.ref<!fir.array<20x10x!fir.logical<4>>>) |
| 179 |
! CHECK: %[[VAL_10:.*]] = arith.constant 1 : i32 |
| 180 |
! CHECK: %[[VAL_11:.*]] = arith.constant 10 : i32 |
| 181 |
! CHECK: hlfir.forall lb { |
| 182 |
! CHECK: hlfir.yield %[[VAL_10]] : i32 |
| 183 |
! CHECK: } ub { |
| 184 |
! CHECK: hlfir.yield %[[VAL_11]] : i32 |
| 185 |
! CHECK: } (%[[VAL_12:.*]]: i32) { |
| 186 |
! CHECK: %[[VAL_13:.*]] = hlfir.forall_index "j" %[[VAL_12]] : (i32) -> !fir.ref<i32> |
| 187 |
! CHECK: hlfir.region_assign { |
| 188 |
! CHECK: %[[VAL_14:.*]] = arith.constant 1 : index |
| 189 |
! CHECK: %[[VAL_15:.*]] = arith.constant 1 : index |
| 190 |
! CHECK: %[[VAL_16:.*]] = arith.constant 20 : index |
| 191 |
! CHECK: %[[VAL_17:.*]] = fir.load %[[VAL_13]] : !fir.ref<i32> |
| 192 |
! CHECK: %[[VAL_18:.*]] = fir.convert %[[VAL_17]] : (i32) -> i64 |
| 193 |
! CHECK: %[[VAL_19:.*]] = fir.shape %[[VAL_16]] : (index) -> !fir.shape<1> |
| 194 |
! CHECK: %[[VAL_20:.*]] = hlfir.designate %[[VAL_9]]#0 (%[[VAL_14]]:%[[VAL_6]]:%[[VAL_15]], %[[VAL_18]]) shape %[[VAL_19]] : (!fir.ref<!fir.array<20x10x!fir.logical<4>>>, index, index, index, i64, !fir.shape<1>) -> !fir.ref<!fir.array<20x!fir.logical<4>>> |
| 195 |
! CHECK: hlfir.yield %[[VAL_20]] : !fir.ref<!fir.array<20x!fir.logical<4>>> |
| 196 |
! CHECK: } to { |
| 197 |
! CHECK: %[[VAL_21:.*]] = arith.constant 1 : index |
| 198 |
! CHECK: %[[VAL_22:.*]] = arith.constant 1 : index |
| 199 |
! CHECK: %[[VAL_23:.*]] = arith.constant 20 : index |
| 200 |
! CHECK: %[[VAL_24:.*]] = fir.load %[[VAL_13]] : !fir.ref<i32> |
| 201 |
! CHECK: %[[VAL_25:.*]] = fir.convert %[[VAL_24]] : (i32) -> i64 |
| 202 |
! CHECK: %[[VAL_26:.*]] = fir.shape %[[VAL_23]] : (index) -> !fir.shape<1> |
| 203 |
! CHECK: %[[VAL_27:.*]] = hlfir.designate %[[VAL_5]]#0 (%[[VAL_21]]:%[[VAL_2]]:%[[VAL_22]], %[[VAL_25]]) shape %[[VAL_26]] : (!fir.ref<!fir.array<20x10xi32>>, index, index, index, i64, !fir.shape<1>) -> !fir.ref<!fir.array<20xi32>> |
| 204 |
! CHECK: hlfir.yield %[[VAL_27]] : !fir.ref<!fir.array<20xi32>> |
| 205 |
! CHECK: } user_defined_assign (%[[VAL_28:.*]]: !fir.ref<!fir.logical<4>>) to (%[[VAL_29:.*]]: !fir.ref<i32>) { |
| 206 |
! CHECK: fir.call @_QPlogical_to_numeric(%[[VAL_29]], %[[VAL_28]]) {{.*}}: (!fir.ref<i32>, !fir.ref<!fir.logical<4>>) -> () |
| 207 |
! CHECK: } |
| 208 |
! CHECK: } |
| 209 |
|
| 210 |
subroutine test_forall_user_def_assignment_non_elemental_array(x, l) |
| 211 |
real :: x(20, 10) |
| 212 |
logical :: l(20, 10) |
| 213 |
forall (j=1:10) x(:, j) = l(:, j) |
| 214 |
end subroutine |
| 215 |
! CHECK-LABEL: func.func @_QMuser_defPtest_forall_user_def_assignment_non_elemental_array( |
| 216 |
! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<!fir.array<20x10xf32>> {fir.bindc_name = "x"}, |
| 217 |
! CHECK-SAME: %[[VAL_1:.*]]: !fir.ref<!fir.array<20x10x!fir.logical<4>>> {fir.bindc_name = "l"}) { |
| 218 |
! CHECK: %[[VAL_2:.*]] = arith.constant 20 : index |
| 219 |
! CHECK: %[[VAL_3:.*]] = arith.constant 10 : index |
| 220 |
! CHECK: %[[VAL_4:.*]] = fir.shape %[[VAL_2]], %[[VAL_3]] : (index, index) -> !fir.shape<2> |
| 221 |
! CHECK: %[[VAL_5:.*]]:2 = hlfir.declare %[[VAL_1]](%[[VAL_4]]) dummy_scope %{{[0-9]+}} {uniq_name = "_QMuser_defFtest_forall_user_def_assignment_non_elemental_arrayEl"} : (!fir.ref<!fir.array<20x10x!fir.logical<4>>>, !fir.shape<2>, !fir.dscope) -> (!fir.ref<!fir.array<20x10x!fir.logical<4>>>, !fir.ref<!fir.array<20x10x!fir.logical<4>>>) |
| 222 |
! CHECK: %[[VAL_6:.*]] = arith.constant 20 : index |
| 223 |
! CHECK: %[[VAL_7:.*]] = arith.constant 10 : index |
| 224 |
! CHECK: %[[VAL_8:.*]] = fir.shape %[[VAL_6]], %[[VAL_7]] : (index, index) -> !fir.shape<2> |
| 225 |
! CHECK: %[[VAL_9:.*]]:2 = hlfir.declare %[[VAL_0]](%[[VAL_8]]) dummy_scope %{{[0-9]+}} {uniq_name = "_QMuser_defFtest_forall_user_def_assignment_non_elemental_arrayEx"} : (!fir.ref<!fir.array<20x10xf32>>, !fir.shape<2>, !fir.dscope) -> (!fir.ref<!fir.array<20x10xf32>>, !fir.ref<!fir.array<20x10xf32>>) |
| 226 |
! CHECK: %[[VAL_10:.*]] = arith.constant 1 : i32 |
| 227 |
! CHECK: %[[VAL_11:.*]] = arith.constant 10 : i32 |
| 228 |
! CHECK: hlfir.forall lb { |
| 229 |
! CHECK: hlfir.yield %[[VAL_10]] : i32 |
| 230 |
! CHECK: } ub { |
| 231 |
! CHECK: hlfir.yield %[[VAL_11]] : i32 |
| 232 |
! CHECK: } (%[[VAL_12:.*]]: i32) { |
| 233 |
! CHECK: %[[VAL_13:.*]] = hlfir.forall_index "j" %[[VAL_12]] : (i32) -> !fir.ref<i32> |
| 234 |
! CHECK: hlfir.region_assign { |
| 235 |
! CHECK: %[[VAL_14:.*]] = arith.constant 1 : index |
| 236 |
! CHECK: %[[VAL_15:.*]] = arith.constant 1 : index |
| 237 |
! CHECK: %[[VAL_16:.*]] = arith.constant 20 : index |
| 238 |
! CHECK: %[[VAL_17:.*]] = fir.load %[[VAL_13]] : !fir.ref<i32> |
| 239 |
! CHECK: %[[VAL_18:.*]] = fir.convert %[[VAL_17]] : (i32) -> i64 |
| 240 |
! CHECK: %[[VAL_19:.*]] = fir.shape %[[VAL_16]] : (index) -> !fir.shape<1> |
| 241 |
! CHECK: %[[VAL_20:.*]] = hlfir.designate %[[VAL_5]]#0 (%[[VAL_14]]:%[[VAL_2]]:%[[VAL_15]], %[[VAL_18]]) shape %[[VAL_19]] : (!fir.ref<!fir.array<20x10x!fir.logical<4>>>, index, index, index, i64, !fir.shape<1>) -> !fir.ref<!fir.array<20x!fir.logical<4>>> |
| 242 |
! CHECK: hlfir.yield %[[VAL_20]] : !fir.ref<!fir.array<20x!fir.logical<4>>> |
| 243 |
! CHECK: } to { |
| 244 |
! CHECK: %[[VAL_21:.*]] = arith.constant 1 : index |
| 245 |
! CHECK: %[[VAL_22:.*]] = arith.constant 1 : index |
| 246 |
! CHECK: %[[VAL_23:.*]] = arith.constant 20 : index |
| 247 |
! CHECK: %[[VAL_24:.*]] = fir.load %[[VAL_13]] : !fir.ref<i32> |
| 248 |
! CHECK: %[[VAL_25:.*]] = fir.convert %[[VAL_24]] : (i32) -> i64 |
| 249 |
! CHECK: %[[VAL_26:.*]] = fir.shape %[[VAL_23]] : (index) -> !fir.shape<1> |
| 250 |
! CHECK: %[[VAL_27:.*]] = hlfir.designate %[[VAL_9]]#0 (%[[VAL_21]]:%[[VAL_6]]:%[[VAL_22]], %[[VAL_25]]) shape %[[VAL_26]] : (!fir.ref<!fir.array<20x10xf32>>, index, index, index, i64, !fir.shape<1>) -> !fir.ref<!fir.array<20xf32>> |
| 251 |
! CHECK: hlfir.yield %[[VAL_27]] : !fir.ref<!fir.array<20xf32>> |
| 252 |
! CHECK: } user_defined_assign (%[[VAL_28:.*]]: !fir.ref<!fir.array<20x!fir.logical<4>>>) to (%[[VAL_29:.*]]: !fir.ref<!fir.array<20xf32>>) { |
| 253 |
! CHECK: %[[VAL_30:.*]] = arith.constant 20 : index |
| 254 |
! CHECK: %[[VAL_31:.*]] = fir.shape %[[VAL_30]] : (index) -> !fir.shape<1> |
| 255 |
! CHECK: %[[VAL_32:.*]] = fir.embox %[[VAL_29]](%[[VAL_31]]) : (!fir.ref<!fir.array<20xf32>>, !fir.shape<1>) -> !fir.box<!fir.array<20xf32>> |
| 256 |
! CHECK: %[[VAL_33:.*]] = fir.convert %[[VAL_32]] : (!fir.box<!fir.array<20xf32>>) -> !fir.box<!fir.array<?xf32>> |
| 257 |
! CHECK: %[[VAL_34:.*]] = arith.constant 20 : index |
| 258 |
! CHECK: %[[VAL_35:.*]] = fir.shape %[[VAL_34]] : (index) -> !fir.shape<1> |
| 259 |
! CHECK: %[[VAL_36:.*]] = fir.embox %[[VAL_28]](%[[VAL_35]]) : (!fir.ref<!fir.array<20x!fir.logical<4>>>, !fir.shape<1>) -> !fir.box<!fir.array<20x!fir.logical<4>>> |
| 260 |
! CHECK: %[[VAL_37:.*]] = fir.convert %[[VAL_36]] : (!fir.box<!fir.array<20x!fir.logical<4>>>) -> !fir.box<!fir.array<?x!fir.logical<4>>> |
| 261 |
! CHECK: fir.call @_QPlogical_array_to_real(%[[VAL_33]], %[[VAL_37]]) {{.*}}: (!fir.box<!fir.array<?xf32>>, !fir.box<!fir.array<?x!fir.logical<4>>>) -> () |
| 262 |
! CHECK: } |
| 263 |
|
| 264 |
subroutine test_pointer(p, x) |
| 265 |
integer, pointer :: p(:) |
| 266 |
real :: x(:, :) |
| 267 |
p = x |
| 268 |
end subroutine |
| 269 |
! CHECK-LABEL: func.func @_QMuser_defPtest_pointer( |
| 270 |
! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<!fir.box<!fir.ptr<!fir.array<?xi32>>>> {fir.bindc_name = "p"}, |
| 271 |
! CHECK-SAME: %[[VAL_1:.*]]: !fir.box<!fir.array<?x?xf32>> {fir.bindc_name = "x"}) { |
| 272 |
! CHECK: %[[VAL_2:.*]]:2 = hlfir.declare %[[VAL_0]] dummy_scope %{{[0-9]+}} {fortran_attrs = #fir.var_attrs<pointer>, uniq_name = "_QMuser_defFtest_pointerEp"} : (!fir.ref<!fir.box<!fir.ptr<!fir.array<?xi32>>>>, !fir.dscope) -> (!fir.ref<!fir.box<!fir.ptr<!fir.array<?xi32>>>>, !fir.ref<!fir.box<!fir.ptr<!fir.array<?xi32>>>>) |
| 273 |
! CHECK: %[[VAL_3:.*]]:2 = hlfir.declare %[[VAL_1]] dummy_scope %{{[0-9]+}} {uniq_name = "_QMuser_defFtest_pointerEx"} : (!fir.box<!fir.array<?x?xf32>>, !fir.dscope) -> (!fir.box<!fir.array<?x?xf32>>, !fir.box<!fir.array<?x?xf32>>) |
| 274 |
! CHECK: hlfir.region_assign { |
| 275 |
! CHECK: hlfir.yield %[[VAL_3]]#0 : !fir.box<!fir.array<?x?xf32>> |
| 276 |
! CHECK: } to { |
| 277 |
! CHECK: hlfir.yield %[[VAL_2]]#0 : !fir.ref<!fir.box<!fir.ptr<!fir.array<?xi32>>>> |
| 278 |
! CHECK: } user_defined_assign (%[[VAL_4:.*]]: !fir.box<!fir.array<?x?xf32>>) to (%[[VAL_5:.*]]: !fir.ref<!fir.box<!fir.ptr<!fir.array<?xi32>>>>) { |
| 279 |
! CHECK: fir.call @_QPreal_to_int_pointer(%[[VAL_5]], %[[VAL_4]]) {{.*}}: (!fir.ref<!fir.box<!fir.ptr<!fir.array<?xi32>>>>, !fir.box<!fir.array<?x?xf32>>) -> () |
| 280 |
! CHECK: } |
| 281 |
|
| 282 |
subroutine test_allocatable(a, x) |
| 283 |
integer, allocatable :: a(:,:) |
| 284 |
real :: x(:) |
| 285 |
a = x |
| 286 |
end subroutine |
| 287 |
! CHECK-LABEL: func.func @_QMuser_defPtest_allocatable( |
| 288 |
! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<!fir.box<!fir.heap<!fir.array<?x?xi32>>>> {fir.bindc_name = "a"}, |
| 289 |
! CHECK-SAME: %[[VAL_1:.*]]: !fir.box<!fir.array<?xf32>> {fir.bindc_name = "x"}) { |
| 290 |
! CHECK: %[[VAL_2:.*]]:2 = hlfir.declare %[[VAL_0]] dummy_scope %{{[0-9]+}} {fortran_attrs = #fir.var_attrs<allocatable>, uniq_name = "_QMuser_defFtest_allocatableEa"} : (!fir.ref<!fir.box<!fir.heap<!fir.array<?x?xi32>>>>, !fir.dscope) -> (!fir.ref<!fir.box<!fir.heap<!fir.array<?x?xi32>>>>, !fir.ref<!fir.box<!fir.heap<!fir.array<?x?xi32>>>>) |
| 291 |
! CHECK: %[[VAL_3:.*]]:2 = hlfir.declare %[[VAL_1]] dummy_scope %{{[0-9]+}} {uniq_name = "_QMuser_defFtest_allocatableEx"} : (!fir.box<!fir.array<?xf32>>, !fir.dscope) -> (!fir.box<!fir.array<?xf32>>, !fir.box<!fir.array<?xf32>>) |
| 292 |
! CHECK: hlfir.region_assign { |
| 293 |
! CHECK: hlfir.yield %[[VAL_3]]#0 : !fir.box<!fir.array<?xf32>> |
| 294 |
! CHECK: } to { |
| 295 |
! CHECK: hlfir.yield %[[VAL_2]]#0 : !fir.ref<!fir.box<!fir.heap<!fir.array<?x?xi32>>>> |
| 296 |
! CHECK: } user_defined_assign (%[[VAL_4:.*]]: !fir.box<!fir.array<?xf32>>) to (%[[VAL_5:.*]]: !fir.ref<!fir.box<!fir.heap<!fir.array<?x?xi32>>>>) { |
| 297 |
! CHECK: fir.call @_QPreal_to_int_allocatable(%[[VAL_5]], %[[VAL_4]]) {{.*}}: (!fir.ref<!fir.box<!fir.heap<!fir.array<?x?xi32>>>>, !fir.box<!fir.array<?xf32>>) -> () |
| 298 |
! CHECK: } |
| 299 |
|
| 300 |
end module |
| 301 |
|
| 302 |
subroutine test_char_get_length(ch) |
| 303 |
integer :: x |
| 304 |
interface assignment(=) |
| 305 |
subroutine test_char_get_length_callee(a,b) |
| 306 |
integer, intent(out) :: a |
| 307 |
character, intent(in) :: b |
| 308 |
end subroutine test_char_get_length_callee |
| 309 |
end interface assignment(=) |
| 310 |
character(*) :: ch |
| 311 |
x = 'abc'//ch |
| 312 |
end subroutine test_char_get_length |
| 313 |
! CHECK-LABEL: func.func @_QPtest_char_get_length( |
| 314 |
! CHECK-SAME: %[[VAL_0:.*]]: !fir.boxchar<1> {fir.bindc_name = "ch"}) { |
| 315 |
! CHECK: %[[VAL_1:.*]]:2 = fir.unboxchar %[[VAL_0]] : (!fir.boxchar<1>) -> (!fir.ref<!fir.char<1,?>>, index) |
| 316 |
! CHECK: %[[VAL_2:.*]]:2 = hlfir.declare %[[VAL_1]]#0 typeparams %[[VAL_1]]#1 dummy_scope %{{[0-9]+}} {uniq_name = "_QFtest_char_get_lengthEch"} : (!fir.ref<!fir.char<1,?>>, index, !fir.dscope) -> (!fir.boxchar<1>, !fir.ref<!fir.char<1,?>>) |
| 317 |
! CHECK: %[[VAL_3:.*]] = fir.alloca i32 {bindc_name = "x", uniq_name = "_QFtest_char_get_lengthEx"} |
| 318 |
! CHECK: %[[VAL_4:.*]]:2 = hlfir.declare %[[VAL_3]] {uniq_name = "_QFtest_char_get_lengthEx"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>) |
| 319 |
! CHECK: hlfir.region_assign { |
| 320 |
! CHECK: %[[VAL_5:.*]] = fir.address_of(@_QQclX616263) : !fir.ref<!fir.char<1,3>> |
| 321 |
! CHECK: %[[VAL_6:.*]] = arith.constant 3 : index |
| 322 |
! CHECK: %[[VAL_7:.*]]:2 = hlfir.declare %[[VAL_5]] typeparams %[[VAL_6]] {fortran_attrs = #fir.var_attrs<parameter>, uniq_name = "_QQclX616263"} : (!fir.ref<!fir.char<1,3>>, index) -> (!fir.ref<!fir.char<1,3>>, !fir.ref<!fir.char<1,3>>) |
| 323 |
! CHECK: %[[VAL_8:.*]] = arith.addi %[[VAL_6]], %[[VAL_1]]#1 : index |
| 324 |
! CHECK: %[[VAL_9:.*]] = hlfir.concat %[[VAL_7]]#0, %[[VAL_2]]#0 len %[[VAL_8]] : (!fir.ref<!fir.char<1,3>>, !fir.boxchar<1>, index) -> !hlfir.expr<!fir.char<1,?>> |
| 325 |
! CHECK: hlfir.yield %[[VAL_9]] : !hlfir.expr<!fir.char<1,?>> |
| 326 |
! CHECK: } to { |
| 327 |
! CHECK: hlfir.yield %[[VAL_4]]#0 : !fir.ref<i32> |
| 328 |
! CHECK: } user_defined_assign (%[[VAL_10:.*]]: !hlfir.expr<!fir.char<1,?>>) to (%[[VAL_11:.*]]: !fir.ref<i32>) { |
| 329 |
! CHECK: %[[VAL_12:.*]] = hlfir.get_length %[[VAL_10]] : (!hlfir.expr<!fir.char<1,?>>) -> index |
| 330 |
! CHECK: %[[VAL_13:.*]]:3 = hlfir.associate %[[VAL_10]] typeparams %[[VAL_12]] {adapt.valuebyref} : (!hlfir.expr<!fir.char<1,?>>, index) -> (!fir.boxchar<1>, !fir.ref<!fir.char<1,?>>, i1) |
| 331 |
! CHECK: fir.call @_QPtest_char_get_length_callee(%[[VAL_11]], %[[VAL_13]]#0) fastmath<contract> : (!fir.ref<i32>, !fir.boxchar<1>) -> () |
| 332 |
! CHECK: hlfir.end_associate %[[VAL_13]]#1, %[[VAL_13]]#2 : !fir.ref<!fir.char<1,?>>, i1 |
| 333 |
! CHECK: } |
| 334 |
! CHECK: return |
| 335 |
! CHECK: } |