| 1 |
! Test lowering of designators to HLFIR |
| 2 |
! RUN: bbc -emit-hlfir -o - %s 2>&1 | FileCheck %s |
| 3 |
|
| 4 |
subroutine array_ref(x, n) |
| 5 |
real :: x(:) |
| 6 |
integer(8) :: n |
| 7 |
print *, x(n) |
| 8 |
end subroutine |
| 9 |
! CHECK-LABEL: func.func @_QParray_ref( |
| 10 |
! CHECK: %[[VAL_2:.*]]:2 = hlfir.declare %{{.*}} dummy_scope %{{[0-9]+}} {uniq_name = "_QFarray_refEn"} : (!fir.ref<i64>, !fir.dscope) -> (!fir.ref<i64>, !fir.ref<i64>) |
| 11 |
! CHECK: %[[VAL_3:.*]]:2 = hlfir.declare %{{.*}} dummy_scope %{{[0-9]+}} {uniq_name = "_QFarray_refEx"} : (!fir.box<!fir.array<?xf32>>, !fir.dscope) -> (!fir.box<!fir.array<?xf32>>, !fir.box<!fir.array<?xf32>>) |
| 12 |
! CHECK: %[[VAL_9:.*]] = fir.load %[[VAL_2]]#0 : !fir.ref<i64> |
| 13 |
! CHECK: %[[VAL_10:.*]] = hlfir.designate %[[VAL_3]]#0 (%[[VAL_9]]) : (!fir.box<!fir.array<?xf32>>, i64) -> !fir.ref<f32> |
| 14 |
|
| 15 |
subroutine char_array_ref(x, n) |
| 16 |
character(*) :: x(:) |
| 17 |
print *, x(10) |
| 18 |
end subroutine |
| 19 |
! CHECK-LABEL: func.func @_QPchar_array_ref( |
| 20 |
! CHECK: %[[VAL_2:.*]]:2 = hlfir.declare %{{.*}} dummy_scope %{{[0-9]+}} {uniq_name = "_QFchar_array_refEn"} : (!fir.ref<i32>, !fir.dscope) -> (!fir.ref<i32>, !fir.ref<i32>) |
| 21 |
! CHECK: %[[VAL_3:.*]]:2 = hlfir.declare %{{.*}} dummy_scope %{{[0-9]+}} {uniq_name = "_QFchar_array_refEx"} : (!fir.box<!fir.array<?x!fir.char<1,?>>>, !fir.dscope) -> (!fir.box<!fir.array<?x!fir.char<1,?>>>, !fir.box<!fir.array<?x!fir.char<1,?>>>) |
| 22 |
! CHECK: %[[VAL_9:.*]] = fir.box_elesize %[[VAL_3]]#1 : (!fir.box<!fir.array<?x!fir.char<1,?>>>) -> index |
| 23 |
! CHECK: %[[VAL_10:.*]] = arith.constant 10 : index |
| 24 |
! CHECK: %[[VAL_11:.*]] = hlfir.designate %[[VAL_3]]#0 (%[[VAL_10]]) typeparams %[[VAL_9]] : (!fir.box<!fir.array<?x!fir.char<1,?>>>, index, index) -> !fir.boxchar<1> |
| 25 |
|
| 26 |
subroutine char_array_ref_cst_len(x, n) |
| 27 |
character(5) :: x(:) |
| 28 |
print *, x(10) |
| 29 |
end subroutine |
| 30 |
! CHECK-LABEL: func.func @_QPchar_array_ref_cst_len( |
| 31 |
! CHECK: %[[VAL_2:.*]]:2 = hlfir.declare %{{.*}} dummy_scope %{{[0-9]+}} {uniq_name = "_QFchar_array_ref_cst_lenEn"} : (!fir.ref<i32>, !fir.dscope) -> (!fir.ref<i32>, !fir.ref<i32>) |
| 32 |
! CHECK: %[[VAL_3:.*]] = arith.constant 5 : index |
| 33 |
! CHECK: %[[VAL_4:.*]]:2 = hlfir.declare %{{.*}} typeparams %[[VAL_3]] dummy_scope %{{[0-9]+}} {uniq_name = "_QFchar_array_ref_cst_lenEx"} : (!fir.box<!fir.array<?x!fir.char<1,5>>>, index, !fir.dscope) -> (!fir.box<!fir.array<?x!fir.char<1,5>>>, !fir.box<!fir.array<?x!fir.char<1,5>>>) |
| 34 |
! CHECK: %[[VAL_10:.*]] = arith.constant 10 : index |
| 35 |
! CHECK: %[[VAL_11:.*]] = hlfir.designate %[[VAL_4]]#0 (%[[VAL_10]]) typeparams %[[VAL_3]] : (!fir.box<!fir.array<?x!fir.char<1,5>>>, index, index) -> !fir.ref<!fir.char<1,5>> |
| 36 |
|
| 37 |
subroutine array_section(x) |
| 38 |
real :: x(10) |
| 39 |
print *, x(2:8:3) |
| 40 |
end subroutine |
| 41 |
! CHECK-LABEL: func.func @_QParray_section( |
| 42 |
! CHECK: %[[VAL_1:.*]] = arith.constant 10 : index |
| 43 |
! CHECK: %[[VAL_2:.*]] = fir.shape %[[VAL_1]] : (index) -> !fir.shape<1> |
| 44 |
! CHECK: %[[VAL_3:.*]]:2 = hlfir.declare %{{.*}}(%[[VAL_2]]) dummy_scope %{{[0-9]+}} {uniq_name = "_QFarray_sectionEx"} : (!fir.ref<!fir.array<10xf32>>, !fir.shape<1>, !fir.dscope) -> (!fir.ref<!fir.array<10xf32>>, !fir.ref<!fir.array<10xf32>>) |
| 45 |
! CHECK: %[[VAL_9:.*]] = arith.constant 2 : index |
| 46 |
! CHECK: %[[VAL_10:.*]] = arith.constant 8 : index |
| 47 |
! CHECK: %[[VAL_11:.*]] = arith.constant 3 : index |
| 48 |
! CHECK: %[[VAL_12:.*]] = arith.constant 3 : index |
| 49 |
! CHECK: %[[VAL_13:.*]] = fir.shape %[[VAL_12]] : (index) -> !fir.shape<1> |
| 50 |
! CHECK: %[[VAL_14:.*]] = hlfir.designate %[[VAL_3]]#0 (%[[VAL_9]]:%[[VAL_10]]:%[[VAL_11]]) shape %[[VAL_13]] : (!fir.ref<!fir.array<10xf32>>, index, index, index, !fir.shape<1>) -> !fir.box<!fir.array<3xf32>> |
| 51 |
|
| 52 |
subroutine array_section_2(x, n) |
| 53 |
real :: x(:) |
| 54 |
integer(8) :: n |
| 55 |
print *, x(n::3) |
| 56 |
end subroutine |
| 57 |
! CHECK-LABEL: func.func @_QParray_section_2( |
| 58 |
! CHECK: %[[VAL_2:.*]]:2 = hlfir.declare %{{.*}} dummy_scope %{{[0-9]+}} {uniq_name = "_QFarray_section_2En"} : (!fir.ref<i64>, !fir.dscope) -> (!fir.ref<i64>, !fir.ref<i64>) |
| 59 |
! CHECK: %[[VAL_3:.*]]:2 = hlfir.declare %{{.*}} dummy_scope %{{[0-9]+}} {uniq_name = "_QFarray_section_2Ex"} : (!fir.box<!fir.array<?xf32>>, !fir.dscope) -> (!fir.box<!fir.array<?xf32>>, !fir.box<!fir.array<?xf32>>) |
| 60 |
! CHECK: %[[VAL_9:.*]] = fir.load %[[VAL_2]]#0 : !fir.ref<i64> |
| 61 |
! CHECK: %[[VAL_10:.*]] = arith.constant 0 : index |
| 62 |
! CHECK: %[[VAL_11:.*]]:3 = fir.box_dims %[[VAL_3]]#1, %[[VAL_10]] : (!fir.box<!fir.array<?xf32>>, index) -> (index, index, index) |
| 63 |
! CHECK: %[[VAL_12:.*]] = fir.convert %[[VAL_9]] : (i64) -> index |
| 64 |
! CHECK: %[[VAL_13:.*]] = arith.constant 3 : index |
| 65 |
! CHECK: %[[VAL_14:.*]] = arith.constant 0 : index |
| 66 |
! CHECK: %[[VAL_15:.*]] = arith.subi %[[VAL_11]]#1, %[[VAL_12]] : index |
| 67 |
! CHECK: %[[VAL_16:.*]] = arith.addi %[[VAL_15]], %[[VAL_13]] : index |
| 68 |
! CHECK: %[[VAL_17:.*]] = arith.divsi %[[VAL_16]], %[[VAL_13]] : index |
| 69 |
! CHECK: %[[VAL_18:.*]] = arith.cmpi sgt, %[[VAL_17]], %[[VAL_14]] : index |
| 70 |
! CHECK: %[[VAL_19:.*]] = arith.select %[[VAL_18]], %[[VAL_17]], %[[VAL_14]] : index |
| 71 |
! CHECK: %[[VAL_20:.*]] = fir.shape %[[VAL_19]] : (index) -> !fir.shape<1> |
| 72 |
! CHECK: %[[VAL_21:.*]] = hlfir.designate %[[VAL_3]]#0 (%[[VAL_12]]:%[[VAL_11]]#1:%[[VAL_13]]) shape %[[VAL_20]] : (!fir.box<!fir.array<?xf32>>, index, index, index, !fir.shape<1>) -> !fir.box<!fir.array<?xf32>> |
| 73 |
|
| 74 |
subroutine char_array_section(x, n) |
| 75 |
character(*) :: x(:) |
| 76 |
print *, x(::3) |
| 77 |
end subroutine |
| 78 |
! CHECK-LABEL: func.func @_QPchar_array_section( |
| 79 |
! CHECK: %[[VAL_2:.*]]:2 = hlfir.declare %{{.*}} dummy_scope %{{[0-9]+}} {uniq_name = "_QFchar_array_sectionEn"} : (!fir.ref<i32>, !fir.dscope) -> (!fir.ref<i32>, !fir.ref<i32>) |
| 80 |
! CHECK: %[[VAL_3:.*]]:2 = hlfir.declare %{{.*}} dummy_scope %{{[0-9]+}} {uniq_name = "_QFchar_array_sectionEx"} : (!fir.box<!fir.array<?x!fir.char<1,?>>>, !fir.dscope) -> (!fir.box<!fir.array<?x!fir.char<1,?>>>, !fir.box<!fir.array<?x!fir.char<1,?>>>) |
| 81 |
! CHECK: %[[VAL_9:.*]] = fir.box_elesize %[[VAL_3]]#1 : (!fir.box<!fir.array<?x!fir.char<1,?>>>) -> index |
| 82 |
! CHECK: %[[VAL_10:.*]] = arith.constant 1 : index |
| 83 |
! CHECK: %[[VAL_11:.*]] = arith.constant 0 : index |
| 84 |
! CHECK: %[[VAL_12:.*]]:3 = fir.box_dims %[[VAL_3]]#1, %[[VAL_11]] : (!fir.box<!fir.array<?x!fir.char<1,?>>>, index) -> (index, index, index) |
| 85 |
! CHECK: %[[VAL_13:.*]] = arith.constant 3 : index |
| 86 |
! CHECK: %[[VAL_14:.*]] = arith.constant 0 : index |
| 87 |
! CHECK: %[[VAL_15:.*]] = arith.subi %[[VAL_12]]#1, %[[VAL_10]] : index |
| 88 |
! CHECK: %[[VAL_16:.*]] = arith.addi %[[VAL_15]], %[[VAL_13]] : index |
| 89 |
! CHECK: %[[VAL_17:.*]] = arith.divsi %[[VAL_16]], %[[VAL_13]] : index |
| 90 |
! CHECK: %[[VAL_18:.*]] = arith.cmpi sgt, %[[VAL_17]], %[[VAL_14]] : index |
| 91 |
! CHECK: %[[VAL_19:.*]] = arith.select %[[VAL_18]], %[[VAL_17]], %[[VAL_14]] : index |
| 92 |
! CHECK: %[[VAL_20:.*]] = fir.shape %[[VAL_19]] : (index) -> !fir.shape<1> |
| 93 |
! CHECK: %[[VAL_21:.*]] = hlfir.designate %[[VAL_3]]#0 (%[[VAL_10]]:%[[VAL_12]]#1:%[[VAL_13]]) shape %[[VAL_20]] typeparams %[[VAL_9]] : (!fir.box<!fir.array<?x!fir.char<1,?>>>, index, index, index, !fir.shape<1>, index) -> !fir.box<!fir.array<?x!fir.char<1,?>>> |
| 94 |
|
| 95 |
subroutine char_array_section_cst_len(x, n) |
| 96 |
character(5) :: x(:) |
| 97 |
print *, x(::3) |
| 98 |
end subroutine |
| 99 |
! CHECK-LABEL: func.func @_QPchar_array_section_cst_len( |
| 100 |
! CHECK: %[[VAL_2:.*]]:2 = hlfir.declare %{{.*}} dummy_scope %{{[0-9]+}} {uniq_name = "_QFchar_array_section_cst_lenEn"} : (!fir.ref<i32>, !fir.dscope) -> (!fir.ref<i32>, !fir.ref<i32>) |
| 101 |
! CHECK: %[[VAL_3:.*]] = arith.constant 5 : index |
| 102 |
! CHECK: %[[VAL_4:.*]]:2 = hlfir.declare %{{.*}} typeparams %[[VAL_3]] dummy_scope %{{[0-9]+}} {uniq_name = "_QFchar_array_section_cst_lenEx"} : (!fir.box<!fir.array<?x!fir.char<1,5>>>, index, !fir.dscope) -> (!fir.box<!fir.array<?x!fir.char<1,5>>>, !fir.box<!fir.array<?x!fir.char<1,5>>>) |
| 103 |
! CHECK: %[[VAL_10:.*]] = arith.constant 1 : index |
| 104 |
! CHECK: %[[VAL_11:.*]] = arith.constant 0 : index |
| 105 |
! CHECK: %[[VAL_12:.*]]:3 = fir.box_dims %[[VAL_4]]#1, %[[VAL_11]] : (!fir.box<!fir.array<?x!fir.char<1,5>>>, index) -> (index, index, index) |
| 106 |
! CHECK: %[[VAL_13:.*]] = arith.constant 3 : index |
| 107 |
! CHECK: %[[VAL_14:.*]] = arith.constant 0 : index |
| 108 |
! CHECK: %[[VAL_15:.*]] = arith.subi %[[VAL_12]]#1, %[[VAL_10]] : index |
| 109 |
! CHECK: %[[VAL_16:.*]] = arith.addi %[[VAL_15]], %[[VAL_13]] : index |
| 110 |
! CHECK: %[[VAL_17:.*]] = arith.divsi %[[VAL_16]], %[[VAL_13]] : index |
| 111 |
! CHECK: %[[VAL_18:.*]] = arith.cmpi sgt, %[[VAL_17]], %[[VAL_14]] : index |
| 112 |
! CHECK: %[[VAL_19:.*]] = arith.select %[[VAL_18]], %[[VAL_17]], %[[VAL_14]] : index |
| 113 |
! CHECK: %[[VAL_20:.*]] = fir.shape %[[VAL_19]] : (index) -> !fir.shape<1> |
| 114 |
! CHECK: %[[VAL_21:.*]] = hlfir.designate %[[VAL_4]]#0 (%[[VAL_10]]:%[[VAL_12]]#1:%[[VAL_13]]) shape %[[VAL_20]] typeparams %[[VAL_3]] : (!fir.box<!fir.array<?x!fir.char<1,5>>>, index, index, index, !fir.shape<1>, index) -> !fir.box<!fir.array<?x!fir.char<1,5>>> |
| 115 |
|
| 116 |
! Checks related to complex numbers |
| 117 |
|
| 118 |
subroutine complex_imag_ref(x) |
| 119 |
complex :: x(:) |
| 120 |
print *, x%im |
| 121 |
end subroutine |
| 122 |
! CHECK-LABEL: func.func @_QPcomplex_imag_ref( |
| 123 |
! CHECK: %[[VAL_2:.*]]:2 = hlfir.declare %{{.*}} dummy_scope %{{[0-9]+}} {uniq_name = "_QFcomplex_imag_refEx"} : (!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>>>) |
| 124 |
! CHECK: %[[VAL_3:.*]] = fir.shape %[[VAL_4:.*]]#1 : (index) -> !fir.shape<1> |
| 125 |
! CHECK: %[[VAL_5:.*]] = hlfir.designate %[[VAL_2]]#0 imag shape %[[VAL_3]] : (!fir.box<!fir.array<?x!fir.complex<4>>>, !fir.shape<1>) -> !fir.box<!fir.array<?xf32>> |
| 126 |
|
| 127 |
subroutine complex_real_ref(x) |
| 128 |
complex :: x(:) |
| 129 |
print *, x%re |
| 130 |
end subroutine |
| 131 |
! CHECK-LABEL: func.func @_QPcomplex_real_ref( |
| 132 |
! CHECK: %[[VAL_2:.*]]:2 = hlfir.declare %{{.*}} dummy_scope %{{[0-9]+}} {uniq_name = "_QFcomplex_real_refEx"} : (!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>>>) |
| 133 |
! CHECK: %[[VAL_3:.*]] = fir.shape %[[VAL_4:.*]]#1 : (index) -> !fir.shape<1> |
| 134 |
! CHECK: %[[VAL_5:.*]] = hlfir.designate %[[VAL_2]]#0 real shape %[[VAL_3]] : (!fir.box<!fir.array<?x!fir.complex<4>>>, !fir.shape<1>) -> !fir.box<!fir.array<?xf32>> |
| 135 |
|
| 136 |
subroutine complex_individual_ref(x, n) |
| 137 |
complex :: x(:) |
| 138 |
integer :: n |
| 139 |
print *, x(n)%im |
| 140 |
end subroutine |
| 141 |
! CHECK-LABEL: func.func @_QPcomplex_individual_ref( |
| 142 |
! CHECK: %[[VAL_2:.*]]:2 = hlfir.declare %{{.*}} dummy_scope %{{[0-9]+}} {uniq_name = "_QFcomplex_individual_refEn"} : (!fir.ref<i32>, !fir.dscope) -> (!fir.ref<i32>, !fir.ref<i32>) |
| 143 |
! CHECK: %[[VAL_3:.*]]:2 = hlfir.declare %{{.*}} dummy_scope %{{[0-9]+}} {uniq_name = "_QFcomplex_individual_refEx"} : (!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>>>) |
| 144 |
! CHECK: %[[VAL_4:.*]] = fir.load %[[VAL_2]]#0 : !fir.ref<i32> |
| 145 |
! CHECK: %[[VAL_5:.*]] = fir.convert %[[VAL_4]] : (i32) -> i64 |
| 146 |
! CHECK: %[[VAL_6:.*]] = hlfir.designate %{{[0-9]+}}#0 (%[[VAL_5]]) imag : (!fir.box<!fir.array<?x!fir.complex<4>>>, i64) -> !fir.ref<f32> |
| 147 |
|
| 148 |
subroutine complex_slice_ref(x, start, end) |
| 149 |
complex :: x(:) |
| 150 |
integer :: start, end |
| 151 |
print *, x(start:end)%re |
| 152 |
end subroutine |
| 153 |
! CHECK-LABEL: func.func @_QPcomplex_slice_ref( |
| 154 |
! CHECK: %[[VAL_2:.*]]:2 = hlfir.declare %{{.*}} dummy_scope %{{[0-9]+}} {uniq_name = "_QFcomplex_slice_refEend"} : (!fir.ref<i32>, !fir.dscope) -> (!fir.ref<i32>, !fir.ref<i32>) |
| 155 |
! CHECK: %[[VAL_3:.*]]:2 = hlfir.declare %{{.*}} dummy_scope %{{[0-9]+}} {uniq_name = "_QFcomplex_slice_refEstart"} : (!fir.ref<i32>, !fir.dscope) -> (!fir.ref<i32>, !fir.ref<i32>) |
| 156 |
! CHECK: %[[VAL_4:.*]]:2 = hlfir.declare %arg0 dummy_scope %{{[0-9]+}} {uniq_name = "_QFcomplex_slice_refEx"} : (!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>>>) |
| 157 |
! CHECK: %[[VAL_5:.*]] = fir.load %[[VAL_3]]#0 : !fir.ref<i32> |
| 158 |
! CHECK: %[[VAL_6:.*]] = fir.convert %[[VAL_5]] : (i32) -> i64 |
| 159 |
! CHECK: %[[VAL_7:.*]] = fir.load %[[VAL_2]]#0 : !fir.ref<i32> |
| 160 |
! CHECK: %[[VAL_8:.*]] = fir.convert %[[VAL_7]] : (i32) -> i64 |
| 161 |
! CHECK: %[[VAL_9:.*]] = fir.convert %[[VAL_6]] : (i64) -> index |
| 162 |
! CHECK: %[[VAL_10:.*]] = fir.convert %[[VAL_8]] : (i64) -> index |
| 163 |
! CHECK: %[[VAL_11:.*]] = arith.subi %[[VAL_10]], %[[VAL_9]] : index |
| 164 |
! CHECK: %[[VAL_12:.*]] = arith.addi %[[VAL_11]], %{{.*}} : index |
| 165 |
! CHECK: %[[VAL_13:.*]] = arith.divsi %[[VAL_12]], %{{.*}} : index |
| 166 |
! CHECK: %[[VAL_14:.*]] = arith.cmpi sgt, %[[VAL_13]], %{{.*}} : index |
| 167 |
! CHECK: %[[VAL_15:.*]] = arith.select %[[VAL_14]], %[[VAL_13]], %{{.*}} : index |
| 168 |
! CHECK: %[[VAL_16:.*]] = fir.shape %[[VAL_15]] : (index) -> !fir.shape<1> |
| 169 |
! CHECK: %[[VAL_17:.*]] = hlfir.designate %[[VAL_4]]#0 (%[[VAL_9]]:%[[VAL_10]]:%{{.*}}) real shape %[[VAL_16]] : (!fir.box<!fir.array<?x!fir.complex<4>>>, index, index, index, !fir.shape<1>) -> !fir.box<!fir.array<?xf32>> |