| 1 |
! Test lowering of calls to interface with pointer or allocatable |
| 2 |
! assumed rank dummy arguments. |
| 3 |
! RUN: bbc -emit-hlfir -o - %s | FileCheck %s |
| 4 |
|
| 5 |
module ifaces_ptr_alloc |
| 6 |
interface |
| 7 |
subroutine alloc_assumed_rank(y) |
| 8 |
real, allocatable :: y(..) |
| 9 |
end subroutine |
| 10 |
subroutine pointer_assumed_rank(y) |
| 11 |
real, optional, pointer :: y(..) |
| 12 |
end subroutine |
| 13 |
subroutine pointer_assumed_rank2(y) |
| 14 |
real, intent(in), pointer :: y(..) |
| 15 |
end subroutine |
| 16 |
end interface |
| 17 |
end module |
| 18 |
|
| 19 |
subroutine scalar_alloc_to_assumed_rank(x) |
| 20 |
use ifaces_ptr_alloc, only : alloc_assumed_rank |
| 21 |
real, allocatable :: x |
| 22 |
call alloc_assumed_rank(x) |
| 23 |
end subroutine |
| 24 |
! CHECK-LABEL: func.func @_QPscalar_alloc_to_assumed_rank( |
| 25 |
! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<!fir.box<!fir.heap<f32>>> {fir.bindc_name = "x"}) { |
| 26 |
! CHECK: %[[VAL_1:.*]]:2 = hlfir.declare %[[VAL_0]] dummy_scope %{{[0-9]+}} {fortran_attrs = #fir.var_attrs<allocatable>, uniq_name = "_QFscalar_alloc_to_assumed_rankEx"} : (!fir.ref<!fir.box<!fir.heap<f32>>>, !fir.dscope) -> (!fir.ref<!fir.box<!fir.heap<f32>>>, !fir.ref<!fir.box<!fir.heap<f32>>>) |
| 27 |
! CHECK: %[[VAL_2:.*]] = fir.convert %[[VAL_1]]#0 : (!fir.ref<!fir.box<!fir.heap<f32>>>) -> !fir.ref<!fir.box<!fir.heap<!fir.array<*:f32>>>> |
| 28 |
! CHECK: fir.call @_QPalloc_assumed_rank(%[[VAL_2]]) fastmath<contract> : (!fir.ref<!fir.box<!fir.heap<!fir.array<*:f32>>>>) -> () |
| 29 |
|
| 30 |
subroutine r2_alloc_to_assumed_rank(x) |
| 31 |
use ifaces_ptr_alloc, only : alloc_assumed_rank |
| 32 |
real, allocatable :: x(:, :) |
| 33 |
call alloc_assumed_rank(x) |
| 34 |
end subroutine |
| 35 |
! CHECK-LABEL: func.func @_QPr2_alloc_to_assumed_rank( |
| 36 |
! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<!fir.box<!fir.heap<!fir.array<?x?xf32>>>> {fir.bindc_name = "x"}) { |
| 37 |
! CHECK: %[[VAL_1:.*]]:2 = hlfir.declare %[[VAL_0]] dummy_scope %{{[0-9]+}} {fortran_attrs = #fir.var_attrs<allocatable>, uniq_name = "_QFr2_alloc_to_assumed_rankEx"} : (!fir.ref<!fir.box<!fir.heap<!fir.array<?x?xf32>>>>, !fir.dscope) -> (!fir.ref<!fir.box<!fir.heap<!fir.array<?x?xf32>>>>, !fir.ref<!fir.box<!fir.heap<!fir.array<?x?xf32>>>>) |
| 38 |
! CHECK: %[[VAL_2:.*]] = fir.convert %[[VAL_1]]#0 : (!fir.ref<!fir.box<!fir.heap<!fir.array<?x?xf32>>>>) -> !fir.ref<!fir.box<!fir.heap<!fir.array<*:f32>>>> |
| 39 |
! CHECK: fir.call @_QPalloc_assumed_rank(%[[VAL_2]]) fastmath<contract> : (!fir.ref<!fir.box<!fir.heap<!fir.array<*:f32>>>>) -> () |
| 40 |
|
| 41 |
subroutine scalar_pointer_to_assumed_rank(x) |
| 42 |
use ifaces_ptr_alloc, only : pointer_assumed_rank |
| 43 |
real, pointer :: x |
| 44 |
call pointer_assumed_rank(x) |
| 45 |
end subroutine |
| 46 |
! CHECK-LABEL: func.func @_QPscalar_pointer_to_assumed_rank( |
| 47 |
! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<!fir.box<!fir.ptr<f32>>> {fir.bindc_name = "x"}) { |
| 48 |
! CHECK: %[[VAL_1:.*]]:2 = hlfir.declare %[[VAL_0]] dummy_scope %{{[0-9]+}} {fortran_attrs = #fir.var_attrs<pointer>, uniq_name = "_QFscalar_pointer_to_assumed_rankEx"} : (!fir.ref<!fir.box<!fir.ptr<f32>>>, !fir.dscope) -> (!fir.ref<!fir.box<!fir.ptr<f32>>>, !fir.ref<!fir.box<!fir.ptr<f32>>>) |
| 49 |
! CHECK: %[[VAL_2:.*]] = fir.convert %[[VAL_1]]#0 : (!fir.ref<!fir.box<!fir.ptr<f32>>>) -> !fir.ref<!fir.box<!fir.ptr<!fir.array<*:f32>>>> |
| 50 |
! CHECK: fir.call @_QPpointer_assumed_rank(%[[VAL_2]]) fastmath<contract> : (!fir.ref<!fir.box<!fir.ptr<!fir.array<*:f32>>>>) -> () |
| 51 |
|
| 52 |
subroutine r2_pointer_to_assumed_rank(x) |
| 53 |
use ifaces_ptr_alloc, only : pointer_assumed_rank |
| 54 |
real, pointer :: x(:, :) |
| 55 |
call pointer_assumed_rank(x) |
| 56 |
end subroutine |
| 57 |
! CHECK-LABEL: func.func @_QPr2_pointer_to_assumed_rank( |
| 58 |
! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<!fir.box<!fir.ptr<!fir.array<?x?xf32>>>> {fir.bindc_name = "x"}) { |
| 59 |
! CHECK: %[[VAL_1:.*]]:2 = hlfir.declare %[[VAL_0]] dummy_scope %{{[0-9]+}} {fortran_attrs = #fir.var_attrs<pointer>, uniq_name = "_QFr2_pointer_to_assumed_rankEx"} : (!fir.ref<!fir.box<!fir.ptr<!fir.array<?x?xf32>>>>, !fir.dscope) -> (!fir.ref<!fir.box<!fir.ptr<!fir.array<?x?xf32>>>>, !fir.ref<!fir.box<!fir.ptr<!fir.array<?x?xf32>>>>) |
| 60 |
! CHECK: %[[VAL_2:.*]] = fir.convert %[[VAL_1]]#0 : (!fir.ref<!fir.box<!fir.ptr<!fir.array<?x?xf32>>>>) -> !fir.ref<!fir.box<!fir.ptr<!fir.array<*:f32>>>> |
| 61 |
! CHECK: fir.call @_QPpointer_assumed_rank(%[[VAL_2]]) fastmath<contract> : (!fir.ref<!fir.box<!fir.ptr<!fir.array<*:f32>>>>) -> () |
| 62 |
|
| 63 |
subroutine r2_target_to_pointer_assumed_rank(x) |
| 64 |
use ifaces_ptr_alloc, only : pointer_assumed_rank2 |
| 65 |
real, target :: x(:, :) |
| 66 |
call pointer_assumed_rank2(x) |
| 67 |
end subroutine |
| 68 |
! CHECK-LABEL: func.func @_QPr2_target_to_pointer_assumed_rank( |
| 69 |
! CHECK-SAME: %[[VAL_0:.*]]: !fir.box<!fir.array<?x?xf32>> {fir.bindc_name = "x", fir.target}) { |
| 70 |
! CHECK: %[[VAL_1:.*]] = fir.alloca !fir.box<!fir.ptr<!fir.array<?x?xf32>>> |
| 71 |
! CHECK: %[[VAL_2:.*]]:2 = hlfir.declare %[[VAL_0]] dummy_scope %{{[0-9]+}} {fortran_attrs = #fir.var_attrs<target>, uniq_name = "_QFr2_target_to_pointer_assumed_rankEx"} : (!fir.box<!fir.array<?x?xf32>>, !fir.dscope) -> (!fir.box<!fir.array<?x?xf32>>, !fir.box<!fir.array<?x?xf32>>) |
| 72 |
! CHECK: %[[VAL_3:.*]] = fir.rebox %[[VAL_2]]#1 : (!fir.box<!fir.array<?x?xf32>>) -> !fir.box<!fir.ptr<!fir.array<?x?xf32>>> |
| 73 |
! CHECK: fir.store %[[VAL_3]] to %[[VAL_1]] : !fir.ref<!fir.box<!fir.ptr<!fir.array<?x?xf32>>>> |
| 74 |
! CHECK: %[[VAL_4:.*]] = fir.convert %[[VAL_1]] : (!fir.ref<!fir.box<!fir.ptr<!fir.array<?x?xf32>>>>) -> !fir.ref<!fir.box<!fir.ptr<!fir.array<*:f32>>>> |
| 75 |
! CHECK: fir.call @_QPpointer_assumed_rank2(%[[VAL_4]]) fastmath<contract> : (!fir.ref<!fir.box<!fir.ptr<!fir.array<*:f32>>>>) -> () |