1! Test lowering of component reference to HLFIR 2! RUN: bbc -emit-hlfir -o - %s | FileCheck %s 3module comp_ref 4type t1 5 integer :: scalar_i 6 real :: scalar_x 7end type 8 9type t2 10 integer :: scalar_i2 11 type(t1) :: scalar_t1 12end type 13 14type t_char 15 integer :: scalar_i 16 character(5) :: scalar_char 17end type 18 19type t_array 20 integer :: scalar_i 21 real :: array_comp(10,20) 22end type 23 24type t_array_lbs 25 integer :: scalar_i 26 real :: array_comp_lbs(2:11,3:22) 27end type 28 29type t_array_char 30 integer :: scalar_i 31 character(5) :: array_char_comp(10,20) 32end type 33 34type t_complex 35 complex :: array_comp(2:11,3:22) 36end type 37end module 38 39!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 40! Test scalar bases ! 41!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 42 43subroutine test_scalar(a) 44 use comp_ref 45 type(t1) :: a 46 call use_real_scalar(a%scalar_x) 47! CHECK-LABEL: func.func @_QPtest_scalar( 48! CHECK: %[[VAL_1:.*]]:2 = hlfir.declare %[[VAL_0:[a-z0-9]*]] {{.*}}Ea 49! CHECK: %[[VAL_2:.*]] = hlfir.designate %[[VAL_1]]#0{"scalar_x"} : (!fir.ref<!fir.type<_QMcomp_refTt1{scalar_i:i32,scalar_x:f32}>>) -> !fir.ref<f32> 50end subroutine 51 52subroutine test_scalar_char(a) 53 use comp_ref 54 type(t_char) :: a 55 call use_char_scalar(a%scalar_char) 56! CHECK-LABEL: func.func @_QPtest_scalar_char( 57! CHECK: %[[VAL_1:.*]]:2 = hlfir.declare %[[VAL_0:[a-z0-9]*]] {{.*}}Ea 58! CHECK: %[[VAL_2:.*]] = arith.constant 5 : index 59! CHECK: %[[VAL_3:.*]] = hlfir.designate %[[VAL_1]]#0{"scalar_char"} typeparams %[[VAL_2]] : (!fir.ref<!fir.type<_QMcomp_refTt_char{scalar_i:i32,scalar_char:!fir.char<1,5>}>>, index) -> !fir.ref<!fir.char<1,5>> 60end subroutine 61 62subroutine test_scalar_char_substring(a) 63 use comp_ref 64 type(t_char) :: a 65 call use_char_scalar(a%scalar_char(3:)) 66! CHECK-LABEL: func.func @_QPtest_scalar_char_substring( 67! CHECK: %[[VAL_1:.*]]:2 = hlfir.declare %[[VAL_0:[a-z0-9]*]] {{.*}}Ea 68! CHECK: %[[VAL_2:.*]] = arith.constant 3 : index 69! CHECK: %[[VAL_3:.*]] = arith.constant 5 : index 70! CHECK: %[[VAL_4:.*]] = arith.constant 3 : index 71! CHECK: %[[VAL_5:.*]] = hlfir.designate %[[VAL_1]]#0{"scalar_char"} substr %[[VAL_2]], %[[VAL_3]] typeparams %[[VAL_4]] : (!fir.ref<!fir.type<_QMcomp_refTt_char{scalar_i:i32,scalar_char:!fir.char<1,5>}>>, index, index, index) -> !fir.ref<!fir.char<1,3>> 72end subroutine 73 74subroutine test_array_comp_1(a) 75 use comp_ref 76 type(t_array) :: a 77 call use_real_array(a%array_comp) 78! CHECK-LABEL: func.func @_QPtest_array_comp_1( 79! CHECK: %[[VAL_1:.*]]:2 = hlfir.declare %[[VAL_0:[a-z0-9]*]] {{.*}}Ea 80! CHECK: %[[VAL_2:.*]] = arith.constant 10 : index 81! CHECK: %[[VAL_3:.*]] = arith.constant 20 : index 82! CHECK: %[[VAL_4:.*]] = fir.shape %[[VAL_2]], %[[VAL_3]] : (index, index) -> !fir.shape<2> 83! CHECK: %[[VAL_5:.*]] = hlfir.designate %[[VAL_1]]#0{"array_comp"} shape %[[VAL_4]] : (!fir.ref<!fir.type<_QMcomp_refTt_array{scalar_i:i32,array_comp:!fir.array<10x20xf32>}>>, !fir.shape<2>) -> !fir.ref<!fir.array<10x20xf32>> 84end subroutine 85 86subroutine test_array_comp_slice(a) 87 use comp_ref 88 type(t_array) :: a 89 ! Contiguous 90 call use_real_array(a%array_comp(:, 4:20:1)) 91! CHECK-LABEL: func.func @_QPtest_array_comp_slice( 92! CHECK: %[[VAL_1:.*]]:2 = hlfir.declare %[[VAL_0:[a-z0-9]*]] {{.*}}Ea 93! CHECK: %[[VAL_2:.*]] = arith.constant 10 : index 94! CHECK: %[[VAL_3:.*]] = arith.constant 20 : index 95! CHECK: %[[VAL_4:.*]] = fir.shape %[[VAL_2]], %[[VAL_3]] : (index, index) -> !fir.shape<2> 96! CHECK: %[[VAL_5:.*]] = arith.constant 1 : index 97! CHECK: %[[VAL_6:.*]] = arith.constant 1 : index 98! CHECK: %[[VAL_7:.*]] = arith.constant 10 : index 99! CHECK: %[[VAL_8:.*]] = arith.constant 4 : index 100! CHECK: %[[VAL_9:.*]] = arith.constant 20 : index 101! CHECK: %[[VAL_10:.*]] = arith.constant 1 : index 102! CHECK: %[[VAL_11:.*]] = arith.constant 17 : index 103! CHECK: %[[VAL_12:.*]] = fir.shape %[[VAL_7]], %[[VAL_11]] : (index, index) -> !fir.shape<2> 104! CHECK: %[[VAL_13:.*]] = hlfir.designate %[[VAL_1]]#0{"array_comp"} <%[[VAL_4]]> (%[[VAL_5]]:%[[VAL_2]]:%[[VAL_6]], %[[VAL_8]]:%[[VAL_9]]:%[[VAL_10]]) shape %[[VAL_12]] : (!fir.ref<!fir.type<_QMcomp_refTt_array{scalar_i:i32,array_comp:!fir.array<10x20xf32>}>>, !fir.shape<2>, index, index, index, index, index, index, !fir.shape<2>) -> !fir.ref<!fir.array<10x17xf32>> 105end subroutine 106 107subroutine test_array_comp_non_contiguous_slice(a) 108 use comp_ref 109 type(t_array) :: a 110 ! Not contiguous 111 print *, a%array_comp(1:6:1, 4:20:1) 112! CHECK-LABEL: func.func @_QPtest_array_comp_non_contiguous_slice( 113! CHECK: %[[VAL_1:.*]]:2 = hlfir.declare %[[VAL_0:[a-z0-9]*]] {{.*}}Ea 114! CHECK: %[[VAL_7:.*]] = arith.constant 10 : index 115! CHECK: %[[VAL_8:.*]] = arith.constant 20 : index 116! CHECK: %[[VAL_9:.*]] = fir.shape %[[VAL_7]], %[[VAL_8]] : (index, index) -> !fir.shape<2> 117! CHECK: %[[VAL_10:.*]] = arith.constant 1 : index 118! CHECK: %[[VAL_11:.*]] = arith.constant 6 : index 119! CHECK: %[[VAL_12:.*]] = arith.constant 1 : index 120! CHECK: %[[VAL_13:.*]] = arith.constant 6 : index 121! CHECK: %[[VAL_14:.*]] = arith.constant 4 : index 122! CHECK: %[[VAL_15:.*]] = arith.constant 20 : index 123! CHECK: %[[VAL_16:.*]] = arith.constant 1 : index 124! CHECK: %[[VAL_17:.*]] = arith.constant 17 : index 125! CHECK: %[[VAL_18:.*]] = fir.shape %[[VAL_13]], %[[VAL_17]] : (index, index) -> !fir.shape<2> 126! CHECK: %[[VAL_19:.*]] = hlfir.designate %[[VAL_1]]#0{"array_comp"} <%[[VAL_9]]> (%[[VAL_10]]:%[[VAL_11]]:%[[VAL_12]], %[[VAL_14]]:%[[VAL_15]]:%[[VAL_16]]) shape %[[VAL_18]] : (!fir.ref<!fir.type<_QMcomp_refTt_array{scalar_i:i32,array_comp:!fir.array<10x20xf32>}>>, !fir.shape<2>, index, index, index, index, index, index, !fir.shape<2>) -> !fir.box<!fir.array<6x17xf32>> 127end subroutine 128 129subroutine test_array_lbs_comp_lbs_1(a) 130 use comp_ref 131 type(t_array_lbs) :: a 132 call use_real_array(a%array_comp_lbs) 133! CHECK-LABEL: func.func @_QPtest_array_lbs_comp_lbs_1( 134! CHECK: %[[VAL_1:.*]]:2 = hlfir.declare %[[VAL_0:[a-z0-9]*]] {{.*}}Ea 135! CHECK: %[[VAL_2:.*]] = arith.constant 10 : index 136! CHECK: %[[VAL_3:.*]] = arith.constant 20 : index 137! CHECK: %[[VAL_4:.*]] = arith.constant 2 : index 138! CHECK: %[[VAL_5:.*]] = arith.constant 3 : index 139! CHECK: %[[VAL_6:.*]] = fir.shape_shift %[[VAL_4]], %[[VAL_2]], %[[VAL_5]], %[[VAL_3]] : (index, index, index, index) -> !fir.shapeshift<2> 140! CHECK: %[[VAL_7:.*]] = hlfir.designate %[[VAL_1]]#0{"array_comp_lbs"} shape %[[VAL_6]] : (!fir.ref<!fir.type<_QMcomp_refTt_array_lbs{scalar_i:i32,array_comp_lbs:!fir.array<10x20xf32>}>>, !fir.shapeshift<2>) -> !fir.box<!fir.array<10x20xf32>> 141end subroutine 142 143subroutine test_array_lbs_comp_lbs_slice(a) 144 use comp_ref 145 type(t_array_lbs) :: a 146 ! Contiguous 147 call use_real_array(a%array_comp_lbs(:, 4:20:1)) 148! CHECK-LABEL: func.func @_QPtest_array_lbs_comp_lbs_slice( 149! CHECK: %[[VAL_1:.*]]:2 = hlfir.declare %[[VAL_0:[a-z0-9]*]] {{.*}}Ea 150! CHECK: %[[VAL_2:.*]] = arith.constant 10 : index 151! CHECK: %[[VAL_3:.*]] = arith.constant 20 : index 152! CHECK: %[[VAL_4:.*]] = arith.constant 2 : index 153! CHECK: %[[VAL_5:.*]] = arith.constant 3 : index 154! CHECK: %[[VAL_6:.*]] = fir.shape_shift %[[VAL_4]], %[[VAL_2]], %[[VAL_5]], %[[VAL_3]] : (index, index, index, index) -> !fir.shapeshift<2> 155! CHECK: %[[VAL_7:.*]] = arith.constant 1 : index 156! CHECK: %[[VAL_8:.*]] = arith.addi %[[VAL_4]], %[[VAL_2]] : index 157! CHECK: %[[VAL_9:.*]] = arith.subi %[[VAL_8]], %[[VAL_7]] : index 158! CHECK: %[[VAL_10:.*]] = arith.constant 1 : index 159! CHECK: %[[VAL_11:.*]] = arith.constant 10 : index 160! CHECK: %[[VAL_12:.*]] = arith.constant 4 : index 161! CHECK: %[[VAL_13:.*]] = arith.constant 20 : index 162! CHECK: %[[VAL_14:.*]] = arith.constant 1 : index 163! CHECK: %[[VAL_15:.*]] = arith.constant 17 : index 164! CHECK: %[[VAL_16:.*]] = fir.shape %[[VAL_11]], %[[VAL_15]] : (index, index) -> !fir.shape<2> 165! CHECK: %[[VAL_17:.*]] = hlfir.designate %[[VAL_1]]#0{"array_comp_lbs"} <%[[VAL_6]]> (%[[VAL_4]]:%[[VAL_9]]:%[[VAL_10]], %[[VAL_12]]:%[[VAL_13]]:%[[VAL_14]]) shape %[[VAL_16]] : (!fir.ref<!fir.type<_QMcomp_refTt_array_lbs{scalar_i:i32,array_comp_lbs:!fir.array<10x20xf32>}>>, !fir.shapeshift<2>, index, index, index, index, index, index, !fir.shape<2>) -> !fir.ref<!fir.array<10x17xf32>> 166end subroutine 167 168subroutine test_array_char_comp_1(a) 169 use comp_ref 170 type(t_array_char) :: a 171 call use_array_char(a%array_char_comp) 172! CHECK-LABEL: func.func @_QPtest_array_char_comp_1( 173! CHECK: %[[VAL_1:.*]]:2 = hlfir.declare %[[VAL_0:[a-z0-9]*]] {{.*}}Ea 174! CHECK: %[[VAL_2:.*]] = arith.constant 10 : index 175! CHECK: %[[VAL_3:.*]] = arith.constant 20 : index 176! CHECK: %[[VAL_4:.*]] = fir.shape %[[VAL_2]], %[[VAL_3]] : (index, index) -> !fir.shape<2> 177! CHECK: %[[VAL_5:.*]] = arith.constant 5 : index 178! CHECK: %[[VAL_6:.*]] = hlfir.designate %[[VAL_1]]#0{"array_char_comp"} shape %[[VAL_4]] typeparams %[[VAL_5]] : (!fir.ref<!fir.type<_QMcomp_refTt_array_char{scalar_i:i32,array_char_comp:!fir.array<10x20x!fir.char<1,5>>}>>, !fir.shape<2>, index) -> !fir.ref<!fir.array<10x20x!fir.char<1,5>>> 179end subroutine 180 181subroutine test_array_char_comp_slice(a) 182 use comp_ref 183 type(t_array_char) :: a 184 ! Contiguous 185 call use_array_char(a%array_char_comp(:, 4:20:1)) 186! CHECK-LABEL: func.func @_QPtest_array_char_comp_slice( 187! CHECK: %[[VAL_1:.*]]:2 = hlfir.declare %[[VAL_0:[a-z0-9]*]] {{.*}}Ea 188! CHECK: %[[VAL_2:.*]] = arith.constant 10 : index 189! CHECK: %[[VAL_3:.*]] = arith.constant 20 : index 190! CHECK: %[[VAL_4:.*]] = fir.shape %[[VAL_2]], %[[VAL_3]] : (index, index) -> !fir.shape<2> 191! CHECK: %[[VAL_5:.*]] = arith.constant 5 : index 192! CHECK: %[[VAL_6:.*]] = arith.constant 1 : index 193! CHECK: %[[VAL_7:.*]] = arith.constant 1 : index 194! CHECK: %[[VAL_8:.*]] = arith.constant 10 : index 195! CHECK: %[[VAL_9:.*]] = arith.constant 4 : index 196! CHECK: %[[VAL_10:.*]] = arith.constant 20 : index 197! CHECK: %[[VAL_11:.*]] = arith.constant 1 : index 198! CHECK: %[[VAL_12:.*]] = arith.constant 17 : index 199! CHECK: %[[VAL_13:.*]] = fir.shape %[[VAL_8]], %[[VAL_12]] : (index, index) -> !fir.shape<2> 200! CHECK: %[[VAL_14:.*]] = hlfir.designate %[[VAL_1]]#0{"array_char_comp"} <%[[VAL_4]]> (%[[VAL_6]]:%[[VAL_2]]:%[[VAL_7]], %[[VAL_9]]:%[[VAL_10]]:%[[VAL_11]]) shape %[[VAL_13]] typeparams %[[VAL_5]] : (!fir.ref<!fir.type<_QMcomp_refTt_array_char{scalar_i:i32,array_char_comp:!fir.array<10x20x!fir.char<1,5>>}>>, !fir.shape<2>, index, index, index, index, index, index, !fir.shape<2>, index) -> !fir.ref<!fir.array<10x17x!fir.char<1,5>>> 201end subroutine 202 203subroutine test_array_char_comp_non_contiguous_slice(a) 204 use comp_ref 205 type(t_array_char) :: a 206 ! Not contiguous 207 print *, a%array_char_comp(1:10:1,1:20:1)(2:4) 208! CHECK-LABEL: func.func @_QPtest_array_char_comp_non_contiguous_slice( 209! CHECK: %[[VAL_1:.*]]:2 = hlfir.declare %[[VAL_0:[a-z0-9]*]] {{.*}}Ea 210! CHECK: %[[VAL_7:.*]] = arith.constant 10 : index 211! CHECK: %[[VAL_8:.*]] = arith.constant 20 : index 212! CHECK: %[[VAL_9:.*]] = fir.shape %[[VAL_7]], %[[VAL_8]] : (index, index) -> !fir.shape<2> 213! CHECK: %[[VAL_10:.*]] = arith.constant 1 : index 214! CHECK: %[[VAL_11:.*]] = arith.constant 10 : index 215! CHECK: %[[VAL_12:.*]] = arith.constant 1 : index 216! CHECK: %[[VAL_13:.*]] = arith.constant 10 : index 217! CHECK: %[[VAL_14:.*]] = arith.constant 1 : index 218! CHECK: %[[VAL_15:.*]] = arith.constant 20 : index 219! CHECK: %[[VAL_16:.*]] = arith.constant 1 : index 220! CHECK: %[[VAL_17:.*]] = arith.constant 20 : index 221! CHECK: %[[VAL_18:.*]] = fir.shape %[[VAL_13]], %[[VAL_17]] : (index, index) -> !fir.shape<2> 222! CHECK: %[[VAL_19:.*]] = arith.constant 2 : index 223! CHECK: %[[VAL_20:.*]] = arith.constant 4 : index 224! CHECK: %[[VAL_21:.*]] = arith.constant 3 : index 225! CHECK: %[[VAL_22:.*]] = hlfir.designate %[[VAL_1]]#0{"array_char_comp"} <%[[VAL_9]]> (%[[VAL_10]]:%[[VAL_11]]:%[[VAL_12]], %[[VAL_14]]:%[[VAL_15]]:%[[VAL_16]]) substr %[[VAL_19]], %[[VAL_20]] shape %[[VAL_18]] typeparams %[[VAL_21]] : (!fir.ref<!fir.type<_QMcomp_refTt_array_char{scalar_i:i32,array_char_comp:!fir.array<10x20x!fir.char<1,5>>}>>, !fir.shape<2>, index, index, index, index, index, index, index, index, !fir.shape<2>, index) -> !fir.box<!fir.array<10x20x!fir.char<1,3>>> 226end subroutine 227 228!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 229! Test array bases ! 230!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 231 232subroutine test_array(a) 233 use comp_ref 234 type(t1) :: a(:) 235 print *, a%scalar_x 236! CHECK-LABEL: func.func @_QPtest_array( 237! CHECK: %[[VAL_1:.*]]:2 = hlfir.declare %[[VAL_0:[a-z0-9]*]] {{.*}}Ea 238! CHECK: %[[VAL_7:.*]] = arith.constant 0 : index 239! CHECK: %[[VAL_8:.*]]:3 = fir.box_dims %[[VAL_1]]#0, %[[VAL_7]] : (!fir.box<!fir.array<?x!fir.type<_QMcomp_refTt1{scalar_i:i32,scalar_x:f32}>>>, index) -> (index, index, index) 240! CHECK: %[[VAL_9:.*]] = fir.shape %[[VAL_8]]#1 : (index) -> !fir.shape<1> 241! CHECK: %[[VAL_10:.*]] = hlfir.designate %[[VAL_1]]#0{"scalar_x"} shape %[[VAL_9]] : (!fir.box<!fir.array<?x!fir.type<_QMcomp_refTt1{scalar_i:i32,scalar_x:f32}>>>, !fir.shape<1>) -> !fir.box<!fir.array<?xf32>> 242end subroutine 243 244subroutine test_array_char(a, n) 245 use comp_ref 246 integer(8) :: n 247 type(t_char) :: a(n) 248 print *, a%scalar_char 249! CHECK-LABEL: func.func @_QPtest_array_char( 250! CHECK: %[[VAL_9:.*]]:2 = hlfir.declare %[[VAL_0:[a-z0-9]*]](%[[VAL_8:[a-z0-9]*]]) {{.*}}Ea 251! CHECK: %[[VAL_15:.*]] = arith.constant 5 : index 252! CHECK: %[[VAL_16:.*]] = hlfir.designate %[[VAL_9]]#0{"scalar_char"} shape %[[VAL_8]] typeparams %[[VAL_15]] : (!fir.box<!fir.array<?x!fir.type<_QMcomp_refTt_char{scalar_i:i32,scalar_char:!fir.char<1,5>}>>>, !fir.shape<1>, index) -> !fir.box<!fir.array<?x!fir.char<1,5>>> 253end subroutine 254 255subroutine test_array_char_substring(a) 256 use comp_ref 257 type(t_char) :: a(100) 258 print *, a%scalar_char(3:) 259! CHECK-LABEL: func.func @_QPtest_array_char_substring( 260! CHECK: %[[VAL_3:.*]]:2 = hlfir.declare %[[VAL_0:[a-z0-9]*]](%[[VAL_2:[a-z0-9]*]]) {{.*}}Ea 261! CHECK: %[[VAL_9:.*]] = arith.constant 3 : index 262! CHECK: %[[VAL_10:.*]] = arith.constant 5 : index 263! CHECK: %[[VAL_11:.*]] = arith.constant 3 : index 264! CHECK: %[[VAL_12:.*]] = hlfir.designate %[[VAL_3]]#0{"scalar_char"} substr %[[VAL_9]], %[[VAL_10]] shape %[[VAL_2]] typeparams %[[VAL_11]] : (!fir.ref<!fir.array<100x!fir.type<_QMcomp_refTt_char{scalar_i:i32,scalar_char:!fir.char<1,5>}>>>, index, index, !fir.shape<1>, index) -> !fir.box<!fir.array<100x!fir.char<1,3>>> 265end subroutine 266 267subroutine test_array_array_comp_1(a) 268 use comp_ref 269 type(t_array) :: a(100) 270 print *, a%array_comp(4,5) 271! CHECK-LABEL: func.func @_QPtest_array_array_comp_1( 272! CHECK: %[[VAL_3:.*]]:2 = hlfir.declare %[[VAL_0:[a-z0-9]*]](%[[VAL_2:[a-z0-9]*]]) {{.*}}Ea 273! CHECK: %[[VAL_9:.*]] = arith.constant 10 : index 274! CHECK: %[[VAL_10:.*]] = arith.constant 20 : index 275! CHECK: %[[VAL_11:.*]] = fir.shape %[[VAL_9]], %[[VAL_10]] : (index, index) -> !fir.shape<2> 276! CHECK: %[[VAL_12:.*]] = arith.constant 4 : index 277! CHECK: %[[VAL_13:.*]] = arith.constant 5 : index 278! CHECK: %[[VAL_14:.*]] = hlfir.designate %[[VAL_3]]#0{"array_comp"} <%[[VAL_11]]> (%[[VAL_12]], %[[VAL_13]]) shape %[[VAL_2]] : (!fir.ref<!fir.array<100x!fir.type<_QMcomp_refTt_array{scalar_i:i32,array_comp:!fir.array<10x20xf32>}>>>, !fir.shape<2>, index, index, !fir.shape<1>) -> !fir.box<!fir.array<100xf32>> 279end subroutine 280 281!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 282! Test several part ref (produces chain of hlfir.designate) ! 283!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 284 285subroutine test_scalar_chain(a) 286 use comp_ref 287 type(t2) :: a 288 call use_real_scalar(a%scalar_t1%scalar_x) 289! CHECK-LABEL: func.func @_QPtest_scalar_chain( 290! CHECK: %[[VAL_1:.*]]:2 = hlfir.declare %[[VAL_0:[a-z0-9]*]] {{.*}}Ea 291! CHECK: %[[VAL_2:.*]] = hlfir.designate %[[VAL_1]]#0{"scalar_t1"} : (!fir.ref<!fir.type<_QMcomp_refTt2{scalar_i2:i32,scalar_t1:!fir.type<_QMcomp_refTt1{scalar_i:i32,scalar_x:f32}>}>>) -> !fir.ref<!fir.type<_QMcomp_refTt1{scalar_i:i32,scalar_x:f32}>> 292! CHECK: %[[VAL_3:.*]] = hlfir.designate %[[VAL_2]]{"scalar_x"} : (!fir.ref<!fir.type<_QMcomp_refTt1{scalar_i:i32,scalar_x:f32}>>) -> !fir.ref<f32> 293end subroutine 294 295subroutine test_array_scalar_chain(a) 296 use comp_ref 297 type(t2) :: a(100) 298 print *, a%scalar_t1%scalar_x 299! CHECK-LABEL: func.func @_QPtest_array_scalar_chain( 300! CHECK: %[[VAL_1:.*]] = arith.constant 100 : index 301! CHECK: %[[VAL_2:.*]] = fir.shape %[[VAL_1]] : (index) -> !fir.shape<1> 302! CHECK: %[[VAL_3:.*]]:2 = hlfir.declare %[[VAL_0:[a-z0-9]*]](%[[VAL_2:[a-z0-9]*]]) {{.*}}Ea 303! CHECK: %[[VAL_9:.*]] = hlfir.designate %[[VAL_3]]#0{"scalar_t1"} shape %[[VAL_2]] : (!fir.ref<!fir.array<100x!fir.type<_QMcomp_refTt2{scalar_i2:i32,scalar_t1:!fir.type<_QMcomp_refTt1{scalar_i:i32,scalar_x:f32}>}>>>, !fir.shape<1>) -> !fir.box<!fir.array<100x!fir.type<_QMcomp_refTt1{scalar_i:i32,scalar_x:f32}>>> 304! CHECK: %[[VAL_10:.*]] = hlfir.designate %[[VAL_9]]{"scalar_x"} shape %[[VAL_2]] : (!fir.box<!fir.array<100x!fir.type<_QMcomp_refTt1{scalar_i:i32,scalar_x:f32}>>>, !fir.shape<1>) -> !fir.box<!fir.array<100xf32>> 305end subroutine 306 307subroutine test_scalar_chain_2(a) 308 use comp_ref 309 type(t1) :: a(50) 310 print *, a(10)%scalar_x 311! CHECK-LABEL: func.func @_QPtest_scalar_chain_2( 312! CHECK: %[[VAL_3:.*]]:2 = hlfir.declare %[[VAL_0:[a-z0-9]*]](%[[VAL_2:[a-z0-9]*]]) {{.*}}Ea 313! CHECK: %[[VAL_9:.*]] = arith.constant 10 : index 314! CHECK: %[[VAL_10:.*]] = hlfir.designate %[[VAL_3]]#0 (%[[VAL_9]]) : (!fir.ref<!fir.array<50x!fir.type<_QMcomp_refTt1{scalar_i:i32,scalar_x:f32}>>>, index) -> !fir.ref<!fir.type<_QMcomp_refTt1{scalar_i:i32,scalar_x:f32}>> 315! CHECK: %[[VAL_11:.*]] = hlfir.designate %[[VAL_10]]{"scalar_x"} : (!fir.ref<!fir.type<_QMcomp_refTt1{scalar_i:i32,scalar_x:f32}>>) -> !fir.ref<f32> 316end subroutine 317 318subroutine test_array_ref_chain(a) 319 use comp_ref 320 type(t_array) :: a(100) 321 print *, a(1:50:5)%array_comp(4,5) 322! CHECK-LABEL: func.func @_QPtest_array_ref_chain( 323! CHECK: %[[VAL_3:.*]]:2 = hlfir.declare %[[VAL_0:[a-z0-9]*]](%[[VAL_2:[a-z0-9]*]]) {{.*}}Ea 324! CHECK: %[[VAL_9:.*]] = arith.constant 1 : index 325! CHECK: %[[VAL_10:.*]] = arith.constant 50 : index 326! CHECK: %[[VAL_11:.*]] = arith.constant 5 : index 327! CHECK: %[[VAL_12:.*]] = arith.constant 10 : index 328! CHECK: %[[VAL_13:.*]] = fir.shape %[[VAL_12]] : (index) -> !fir.shape<1> 329! CHECK: %[[VAL_14:.*]] = hlfir.designate %[[VAL_3]]#0 (%[[VAL_9]]:%[[VAL_10]]:%[[VAL_11]]) shape %[[VAL_13]] : (!fir.ref<!fir.array<100x!fir.type<_QMcomp_refTt_array{scalar_i:i32,array_comp:!fir.array<10x20xf32>}>>>, index, index, index, !fir.shape<1>) -> !fir.box<!fir.array<10x!fir.type<_QMcomp_refTt_array{scalar_i:i32,array_comp:!fir.array<10x20xf32>}>>> 330! CHECK: %[[VAL_15:.*]] = arith.constant 10 : index 331! CHECK: %[[VAL_16:.*]] = arith.constant 20 : index 332! CHECK: %[[VAL_17:.*]] = fir.shape %[[VAL_15]], %[[VAL_16]] : (index, index) -> !fir.shape<2> 333! CHECK: %[[VAL_18:.*]] = arith.constant 4 : index 334! CHECK: %[[VAL_19:.*]] = arith.constant 5 : index 335! CHECK: %[[VAL_20:.*]] = hlfir.designate %[[VAL_14]]{"array_comp"} <%[[VAL_17]]> (%[[VAL_18]], %[[VAL_19]]) shape %[[VAL_13]] : (!fir.box<!fir.array<10x!fir.type<_QMcomp_refTt_array{scalar_i:i32,array_comp:!fir.array<10x20xf32>}>>>, !fir.shape<2>, index, index, !fir.shape<1>) -> !fir.box<!fir.array<10xf32>> 336end subroutine 337 338subroutine test_scalar_array_complex_chain(a) 339 use comp_ref 340 type(t_complex) :: a 341 print *, a%array_comp%im 342! CHECK-LABEL: func.func @_QPtest_scalar_array_complex_chain( 343! CHECK: %[[VAL_1:.*]]:2 = hlfir.declare %[[VAL_0]] dummy_scope %{{[0-9]+}} {uniq_name = "_QFtest_scalar_array_complex_chainEa"} : (!fir.ref<!fir.type<_QMcomp_refTt_complex{array_comp:!fir.array<10x20xcomplex<f32>>}>>, !fir.dscope) -> (!fir.ref<!fir.type<_QMcomp_refTt_complex{array_comp:!fir.array<10x20xcomplex<f32>>}>>, !fir.ref<!fir.type<_QMcomp_refTt_complex{array_comp:!fir.array<10x20xcomplex<f32>>}>>) 344! CHECK: %[[VAL_7:.*]] = arith.constant 10 : index 345! CHECK: %[[VAL_8:.*]] = arith.constant 20 : index 346! CHECK: %[[VAL_9:.*]] = arith.constant 2 : index 347! CHECK: %[[VAL_10:.*]] = arith.constant 3 : index 348! CHECK: %[[VAL_11:.*]] = fir.shape_shift %[[VAL_9]], %[[VAL_7]], %[[VAL_10]], %[[VAL_8]] : (index, index, index, index) -> !fir.shapeshift<2> 349! CHECK: %[[VAL_12:.*]] = arith.constant 1 : index 350! CHECK: %[[VAL_13:.*]] = arith.constant 1 : index 351! CHECK: %[[VAL_14:.*]] = arith.addi %[[VAL_9]], %[[VAL_7]] : index 352! CHECK: %[[VAL_15:.*]] = arith.subi %[[VAL_14]], %[[VAL_13]] : index 353! CHECK: %[[VAL_16:.*]] = arith.addi %[[VAL_10]], %[[VAL_8]] : index 354! CHECK: %[[VAL_17:.*]] = arith.subi %[[VAL_16]], %[[VAL_13]] : index 355! CHECK: %[[VAL_18:.*]] = arith.constant 0 : index 356! CHECK: %[[VAL_19:.*]] = arith.subi %[[VAL_15]], %[[VAL_9]] : index 357! CHECK: %[[VAL_20:.*]] = arith.addi %[[VAL_19]], %[[VAL_12]] : index 358! CHECK: %[[VAL_21:.*]] = arith.divsi %[[VAL_20]], %[[VAL_12]] : index 359! CHECK: %[[VAL_22:.*]] = arith.cmpi sgt, %[[VAL_21]], %[[VAL_18]] : index 360! CHECK: %[[VAL_23:.*]] = arith.select %[[VAL_22]], %[[VAL_21]], %[[VAL_18]] : index 361! CHECK: %[[VAL_24:.*]] = arith.constant 0 : index 362! CHECK: %[[VAL_25:.*]] = arith.subi %[[VAL_17]], %[[VAL_10]] : index 363! CHECK: %[[VAL_26:.*]] = arith.addi %[[VAL_25]], %[[VAL_12]] : index 364! CHECK: %[[VAL_27:.*]] = arith.divsi %[[VAL_26]], %[[VAL_12]] : index 365! CHECK: %[[VAL_28:.*]] = arith.cmpi sgt, %[[VAL_27]], %[[VAL_24]] : index 366! CHECK: %[[VAL_29:.*]] = arith.select %[[VAL_28]], %[[VAL_27]], %[[VAL_24]] : index 367! CHECK: %[[VAL_30:.*]] = fir.shape %[[VAL_23]], %[[VAL_29]] : (index, index) -> !fir.shape<2> 368! CHECK: %[[VAL_31:.*]] = hlfir.designate %[[VAL_1]]#0{"array_comp"} <%[[VAL_11]]> (%[[VAL_9]]:%[[VAL_15]]:%[[VAL_12]], %[[VAL_10]]:%[[VAL_17]]:%[[VAL_12]]) imag shape %[[VAL_30]] : (!fir.ref<!fir.type<_QMcomp_refTt_complex{array_comp:!fir.array<10x20xcomplex<f32>>}>>, !fir.shapeshift<2>, index, index, index, index, index, index, !fir.shape<2>) -> !fir.box<!fir.array<10x20xf32>> 369end subroutine 370 371subroutine test_poly_array_vector_subscript(p, v, r) 372 use comp_ref 373 class(t1),pointer :: p(:) 374 integer v(3) 375 integer r(3) 376 r = p(v)%scalar_i 377end subroutine test_poly_array_vector_subscript 378! CHECK-LABEL: func.func @_QPtest_poly_array_vector_subscript( 379! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<!fir.class<!fir.ptr<!fir.array<?x!fir.type<_QMcomp_refTt1{scalar_i:i32,scalar_x:f32}>>>>> {fir.bindc_name = "p"}, 380! CHECK-SAME: %[[VAL_1:.*]]: !fir.ref<!fir.array<3xi32>> {fir.bindc_name = "v"}, 381! CHECK-SAME: %[[VAL_2:.*]]: !fir.ref<!fir.array<3xi32>> {fir.bindc_name = "r"}) { 382! CHECK: %[[VAL_3:.*]]:2 = hlfir.declare %[[VAL_0]] dummy_scope %{{[0-9]+}} {fortran_attrs = #fir.var_attrs<pointer>, uniq_name = "_QFtest_poly_array_vector_subscriptEp"} : (!fir.ref<!fir.class<!fir.ptr<!fir.array<?x!fir.type<_QMcomp_refTt1{scalar_i:i32,scalar_x:f32}>>>>>, !fir.dscope) -> (!fir.ref<!fir.class<!fir.ptr<!fir.array<?x!fir.type<_QMcomp_refTt1{scalar_i:i32,scalar_x:f32}>>>>>, !fir.ref<!fir.class<!fir.ptr<!fir.array<?x!fir.type<_QMcomp_refTt1{scalar_i:i32,scalar_x:f32}>>>>>) 383! CHECK: %[[VAL_4:.*]] = arith.constant 3 : index 384! CHECK: %[[VAL_5:.*]] = fir.shape %[[VAL_4]] : (index) -> !fir.shape<1> 385! CHECK: %[[VAL_6:.*]]:2 = hlfir.declare %[[VAL_2]](%[[VAL_5]]) dummy_scope %{{[0-9]+}} {uniq_name = "_QFtest_poly_array_vector_subscriptEr"} : (!fir.ref<!fir.array<3xi32>>, !fir.shape<1>, !fir.dscope) -> (!fir.ref<!fir.array<3xi32>>, !fir.ref<!fir.array<3xi32>>) 386! CHECK: %[[VAL_7:.*]] = arith.constant 3 : index 387! CHECK: %[[VAL_8:.*]] = fir.shape %[[VAL_7]] : (index) -> !fir.shape<1> 388! CHECK: %[[VAL_9:.*]]:2 = hlfir.declare %[[VAL_1]](%[[VAL_8]]) dummy_scope %{{[0-9]+}} {uniq_name = "_QFtest_poly_array_vector_subscriptEv"} : (!fir.ref<!fir.array<3xi32>>, !fir.shape<1>, !fir.dscope) -> (!fir.ref<!fir.array<3xi32>>, !fir.ref<!fir.array<3xi32>>) 389! CHECK: %[[VAL_10:.*]] = fir.load %[[VAL_3]]#0 : !fir.ref<!fir.class<!fir.ptr<!fir.array<?x!fir.type<_QMcomp_refTt1{scalar_i:i32,scalar_x:f32}>>>>> 390! CHECK: %[[VAL_11:.*]] = hlfir.elemental %[[VAL_8]] unordered : (!fir.shape<1>) -> !hlfir.expr<3xi64> { 391! CHECK: ^bb0(%[[VAL_12:.*]]: index): 392! CHECK: %[[VAL_13:.*]] = hlfir.designate %[[VAL_9]]#0 (%[[VAL_12]]) : (!fir.ref<!fir.array<3xi32>>, index) -> !fir.ref<i32> 393! CHECK: %[[VAL_14:.*]] = fir.load %[[VAL_13]] : !fir.ref<i32> 394! CHECK: %[[VAL_15:.*]] = fir.convert %[[VAL_14]] : (i32) -> i64 395! CHECK: hlfir.yield_element %[[VAL_15]] : i64 396! CHECK: } 397! CHECK: %[[VAL_16:.*]] = arith.constant 3 : index 398! CHECK: %[[VAL_17:.*]] = fir.shape %[[VAL_16]] : (index) -> !fir.shape<1> 399! CHECK: %[[VAL_18:.*]] = hlfir.elemental %[[VAL_17]] unordered : (!fir.shape<1>) -> !hlfir.expr<3xi32> { 400! CHECK: ^bb0(%[[VAL_19:.*]]: index): 401! CHECK: %[[VAL_20:.*]] = hlfir.apply %[[VAL_11]], %[[VAL_19]] : (!hlfir.expr<3xi64>, index) -> i64 402! CHECK: %[[VAL_21:.*]] = hlfir.designate %[[VAL_10]] (%[[VAL_20]]) : (!fir.class<!fir.ptr<!fir.array<?x!fir.type<_QMcomp_refTt1{scalar_i:i32,scalar_x:f32}>>>>, i64) -> !fir.class<!fir.type<_QMcomp_refTt1{scalar_i:i32,scalar_x:f32}>> 403! CHECK: %[[VAL_22:.*]] = hlfir.designate %[[VAL_21]]{"scalar_i"} : (!fir.class<!fir.type<_QMcomp_refTt1{scalar_i:i32,scalar_x:f32}>>) -> !fir.ref<i32> 404! CHECK: %[[VAL_23:.*]] = fir.load %[[VAL_22]] : !fir.ref<i32> 405! CHECK: hlfir.yield_element %[[VAL_23]] : i32 406! CHECK: } 407! CHECK: hlfir.assign %[[VAL_18]] to %[[VAL_6]]#0 : !hlfir.expr<3xi32>, !fir.ref<!fir.array<3xi32>> 408! CHECK: hlfir.destroy %[[VAL_18]] : !hlfir.expr<3xi32> 409! CHECK: hlfir.destroy %[[VAL_11]] : !hlfir.expr<3xi64> 410! CHECK: return 411! CHECK: } 412