| 1 |
! Test lowering of allocatable and pointer sub-part reference to HLFIR |
| 2 |
! As opposed to whole reference, a pointer/allocatable dereference must |
| 3 |
! be inserted and addressed in a following hlfir.designate to address |
| 4 |
! the sub-part. |
| 5 |
|
| 6 |
! RUN: bbc -emit-hlfir -o - %s -I nw | FileCheck %s |
| 7 |
|
| 8 |
module m |
| 9 |
type t1 |
| 10 |
real :: x |
| 11 |
end type |
| 12 |
type t2 |
| 13 |
type(t1), pointer :: p |
| 14 |
end type |
| 15 |
type t3 |
| 16 |
character(:), allocatable :: a(:) |
| 17 |
end type |
| 18 |
end module |
| 19 |
|
| 20 |
subroutine test_pointer_component_followed_by_component_ref(x) |
| 21 |
use m |
| 22 |
type(t2) :: x |
| 23 |
call takes_real(x%p%x) |
| 24 |
end subroutine |
| 25 |
! CHECK-LABEL: func.func @_QPtest_pointer_component_followed_by_component_ref( |
| 26 |
! CHECK: %[[VAL_1:.*]]:2 = hlfir.declare %{{.*}} {{.*}}Ex |
| 27 |
! CHECK: %[[VAL_2:.*]] = hlfir.designate %[[VAL_1]]#0{"p"} {fortran_attrs = #fir.var_attrs<pointer>} : (!fir.ref<!fir.type<_QMmTt2{p:!fir.box<!fir.ptr<!fir.type<_QMmTt1{x:f32}>>>}>>) -> !fir.ref<!fir.box<!fir.ptr<!fir.type<_QMmTt1{x:f32}>>>> |
| 28 |
! CHECK: %[[VAL_3:.*]] = fir.load %[[VAL_2]] : !fir.ref<!fir.box<!fir.ptr<!fir.type<_QMmTt1{x:f32}>>>> |
| 29 |
! CHECK: %[[VAL_4:.*]] = fir.box_addr %[[VAL_3:.*]] : (!fir.box<!fir.ptr<!fir.type<_QMmTt1{x:f32}>>>) -> !fir.ptr<!fir.type<_QMmTt1{x:f32}>> |
| 30 |
! CHECK: hlfir.designate %[[VAL_4]]{"x"} : (!fir.ptr<!fir.type<_QMmTt1{x:f32}>>) -> !fir.ref<f32> |
| 31 |
|
| 32 |
subroutine test_symbol_followed_by_ref(x) |
| 33 |
character(:), allocatable :: x(:) |
| 34 |
call test_char(x(10)) |
| 35 |
end subroutine |
| 36 |
! CHECK-LABEL: func.func @_QPtest_symbol_followed_by_ref( |
| 37 |
! CHECK: %[[VAL_1:.*]]:2 = hlfir.declare %{{.*}} {fortran_attrs = #fir.var_attrs<allocatable>, uniq_name = {{.*}}Ex" |
| 38 |
! CHECK: %[[VAL_2:.*]] = fir.load %[[VAL_1]]#0 : !fir.ref<!fir.box<!fir.heap<!fir.array<?x!fir.char<1,?>>>>> |
| 39 |
! CHECK: %[[VAL_3:.*]] = fir.box_elesize %[[VAL_2]] : (!fir.box<!fir.heap<!fir.array<?x!fir.char<1,?>>>>) -> index |
| 40 |
! CHECK: %[[VAL_4:.*]] = arith.constant 10 : index |
| 41 |
! CHECK: %[[VAL_5:.*]] = hlfir.designate %[[VAL_2]] (%[[VAL_4]]) typeparams %[[VAL_3]] : (!fir.box<!fir.heap<!fir.array<?x!fir.char<1,?>>>>, index, index) -> !fir.boxchar<1> |
| 42 |
|
| 43 |
subroutine test_component_followed_by_ref(x) |
| 44 |
use m |
| 45 |
type(t3) :: x |
| 46 |
call test_char(x%a(10)) |
| 47 |
end subroutine |
| 48 |
! CHECK-LABEL: func.func @_QPtest_component_followed_by_ref( |
| 49 |
! CHECK: %[[VAL_1:.*]]:2 = hlfir.declare %{{.*}} {{.*}}Ex |
| 50 |
! CHECK: %[[VAL_2:.*]] = hlfir.designate %[[VAL_1]]#0{"a"} {fortran_attrs = #fir.var_attrs<allocatable>} : (!fir.ref<!fir.type<_QMmTt3{a:!fir.box<!fir.heap<!fir.array<?x!fir.char<1,?>>>>}>>) -> !fir.ref<!fir.box<!fir.heap<!fir.array<?x!fir.char<1,?>>>>> |
| 51 |
! CHECK: %[[VAL_3:.*]] = fir.load %[[VAL_2]] : !fir.ref<!fir.box<!fir.heap<!fir.array<?x!fir.char<1,?>>>>> |
| 52 |
! CHECK: %[[VAL_4:.*]] = fir.box_elesize %[[VAL_3]] : (!fir.box<!fir.heap<!fir.array<?x!fir.char<1,?>>>>) -> index |
| 53 |
! CHECK: %[[VAL_5:.*]] = arith.constant 10 : index |
| 54 |
! CHECK: %[[VAL_6:.*]] = hlfir.designate %[[VAL_3]] (%[[VAL_5]]) typeparams %[[VAL_4]] : (!fir.box<!fir.heap<!fir.array<?x!fir.char<1,?>>>>, index, index) -> !fir.boxchar<1> |