| 1 |
! Test implicit conversion in assignment to whole allocatables. It |
| 2 |
! is special because care must be taken to propagate the RHS lower |
| 3 |
! bounds to the LHS in case of re-allocation. |
| 4 |
! RUN: bbc -emit-hlfir %s -o - | FileCheck %s |
| 5 |
|
| 6 |
subroutine preserve_lbounds(x, y) |
| 7 |
integer, allocatable :: x(:) |
| 8 |
complex, allocatable :: y(:) |
| 9 |
x = y |
| 10 |
end subroutine |
| 11 |
! CHECK-LABEL: func.func @_QPpreserve_lbounds( |
| 12 |
! CHECK: %[[VAL_2:.*]]:2 = hlfir.declare {{.*}}uniq_name = "_QFpreserve_lboundsEx" |
| 13 |
! CHECK: %[[VAL_3:.*]]:2 = hlfir.declare {{.*}}uniq_name = "_QFpreserve_lboundsEy" |
| 14 |
! CHECK: %[[VAL_4:.*]] = fir.load %[[VAL_3]]#0 : !fir.ref<!fir.box<!fir.heap<!fir.array<?x!fir.complex<4>>>>> |
| 15 |
! CHECK: %[[VAL_5:.*]] = arith.constant 0 : index |
| 16 |
! CHECK: %[[VAL_6:.*]]:3 = fir.box_dims %[[VAL_4]], %[[VAL_5]] : (!fir.box<!fir.heap<!fir.array<?x!fir.complex<4>>>>, index) -> (index, index, index) |
| 17 |
! CHECK: %[[VAL_7:.*]] = fir.shape %[[VAL_6]]#1 : (index) -> !fir.shape<1> |
| 18 |
! CHECK: %[[VAL_8:.*]] = hlfir.elemental %[[VAL_7]] unordered : (!fir.shape<1>) -> !hlfir.expr<?xi32> { |
| 19 |
! CHECK: ^bb0(%[[VAL_9:.*]]: index): |
| 20 |
! CHECK: %[[VAL_10:.*]] = arith.constant 0 : index |
| 21 |
! CHECK: %[[VAL_11:.*]]:3 = fir.box_dims %[[VAL_4]], %[[VAL_10]] : (!fir.box<!fir.heap<!fir.array<?x!fir.complex<4>>>>, index) -> (index, index, index) |
| 22 |
! CHECK: %[[VAL_12:.*]] = arith.constant 1 : index |
| 23 |
! CHECK: %[[VAL_13:.*]] = arith.subi %[[VAL_11]]#0, %[[VAL_12]] : index |
| 24 |
! CHECK: %[[VAL_14:.*]] = arith.addi %[[VAL_9]], %[[VAL_13]] : index |
| 25 |
! CHECK: %[[VAL_15:.*]] = hlfir.designate %[[VAL_4]] (%[[VAL_14]]) : (!fir.box<!fir.heap<!fir.array<?x!fir.complex<4>>>>, index) -> !fir.ref<!fir.complex<4>> |
| 26 |
! CHECK: %[[VAL_16:.*]] = fir.load %[[VAL_15]] : !fir.ref<!fir.complex<4>> |
| 27 |
! CHECK: %[[VAL_17:.*]] = fir.extract_value %[[VAL_16]], [0 : index] : (!fir.complex<4>) -> f32 |
| 28 |
! CHECK: %[[VAL_18:.*]] = fir.convert %[[VAL_17]] : (f32) -> i32 |
| 29 |
! CHECK: hlfir.yield_element %[[VAL_18]] : i32 |
| 30 |
! CHECK: } |
| 31 |
! CHECK: %[[VAL_19:.*]]:3 = hlfir.associate %[[VAL_8]](%[[VAL_7]]) {uniq_name = ".tmp.keeplbounds"} : (!hlfir.expr<?xi32>, !fir.shape<1>) -> (!fir.box<!fir.array<?xi32>>, !fir.ref<!fir.array<?xi32>>, i1) |
| 32 |
! CHECK: %[[VAL_20:.*]] = arith.constant 0 : index |
| 33 |
! CHECK: %[[VAL_21:.*]]:3 = fir.box_dims %[[VAL_4]], %[[VAL_20]] : (!fir.box<!fir.heap<!fir.array<?x!fir.complex<4>>>>, index) -> (index, index, index) |
| 34 |
! CHECK: %[[VAL_22:.*]] = fir.shape_shift %[[VAL_21]]#0, %[[VAL_6]]#1 : (index, index) -> !fir.shapeshift<1> |
| 35 |
! CHECK: %[[VAL_23:.*]]:2 = hlfir.declare %[[VAL_19]]#1(%[[VAL_22]]) {uniq_name = ".tmp.keeplbounds"} : (!fir.ref<!fir.array<?xi32>>, !fir.shapeshift<1>) -> (!fir.box<!fir.array<?xi32>>, !fir.ref<!fir.array<?xi32>>) |
| 36 |
! CHECK: hlfir.assign %[[VAL_23]]#0 to %[[VAL_2]]#0 realloc : !fir.box<!fir.array<?xi32>>, !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>> |
| 37 |
! CHECK: hlfir.end_associate %[[VAL_19]]#1, %[[VAL_19]]#2 : !fir.ref<!fir.array<?xi32>>, i1 |
| 38 |
! CHECK: hlfir.destroy %[[VAL_8]] : !hlfir.expr<?xi32> |
| 39 |
! CHECK: return |
| 40 |
! CHECK: } |
| 41 |
|
| 42 |
! Test that RHS character length is preserved in a character KIND |
| 43 |
! conversion before the assignment. |
| 44 |
subroutine kind_and_length(a, b) |
| 45 |
character(len=4,kind=4), allocatable :: a(:) |
| 46 |
character(len=2,kind=1) :: b(:) |
| 47 |
a = b |
| 48 |
end subroutine |
| 49 |
! CHECK-LABEL: func.func @_QPkind_and_length( |
| 50 |
! CHECK: %[[VAL_2:.*]] = arith.constant 4 : index |
| 51 |
! CHECK: %[[VAL_3:.*]]:2 = hlfir.declare %[[VAL_0:[a-z0-9]*]] typeparams %[[VAL_2:[a-z0-9]*]] {{.*}}Ea |
| 52 |
! CHECK: %[[VAL_4:.*]] = arith.constant 2 : index |
| 53 |
! CHECK: %[[VAL_5:.*]]:2 = hlfir.declare %[[VAL_1:[a-z0-9]*]] typeparams %[[VAL_4:[a-z0-9]*]] {{.*}}Eb |
| 54 |
! CHECK: %[[VAL_6:.*]] = arith.constant 0 : index |
| 55 |
! CHECK: %[[VAL_7:.*]]:3 = fir.box_dims %[[VAL_5]]#0, %[[VAL_6]] : (!fir.box<!fir.array<?x!fir.char<1,2>>>, index) -> (index, index, index) |
| 56 |
! CHECK: %[[VAL_8:.*]] = fir.shape %[[VAL_7]]#1 : (index) -> !fir.shape<1> |
| 57 |
! CHECK: %[[VAL_9:.*]] = hlfir.elemental %[[VAL_8]] typeparams %[[VAL_4]] unordered : (!fir.shape<1>, index) -> !hlfir.expr<?x!fir.char<4,2>> { |
| 58 |
! CHECK: ^bb0(%[[VAL_10:.*]]: index): |
| 59 |
! CHECK: %[[VAL_11:.*]] = hlfir.designate %[[VAL_5]]#0 (%[[VAL_10]]) typeparams %[[VAL_4]] : (!fir.box<!fir.array<?x!fir.char<1,2>>>, index, index) -> !fir.ref<!fir.char<1,2>> |
| 60 |
! CHECK: %[[VAL_12:.*]] = fir.alloca !fir.char<4,?>(%[[VAL_4]] : index) |
| 61 |
! CHECK: fir.char_convert %[[VAL_11]] for %[[VAL_4]] to %[[VAL_12]] : !fir.ref<!fir.char<1,2>>, index, !fir.ref<!fir.char<4,?>> |
| 62 |
! CHECK: %[[VAL_13:.*]]:2 = hlfir.declare %[[VAL_12:[a-z0-9]*]] typeparams %[[VAL_4:[a-z0-9]*]] {uniq_name = ".temp.kindconvert"} : (!fir.ref<!fir.char<4,?>>, index) -> (!fir.boxchar<4>, !fir.ref<!fir.char<4,?>>) |
| 63 |
! CHECK: hlfir.yield_element %[[VAL_13]]#0 : !fir.boxchar<4> |
| 64 |
! CHECK: } |
| 65 |
! CHECK: hlfir.assign %[[VAL_9]] to %[[VAL_3]]#0 realloc keep_lhs_len : !hlfir.expr<?x!fir.char<4,2>>, !fir.ref<!fir.box<!fir.heap<!fir.array<?x!fir.char<4,4>>>>> |
| 66 |
|