| 1 |
! Test lowering of assumed-rank variables |
| 2 |
! RUN: bbc -emit-hlfir %s -allow-assumed-rank -o - | FileCheck %s |
| 3 |
|
| 4 |
module assumed_rank_tests |
| 5 |
interface |
| 6 |
subroutine takes_real(x) |
| 7 |
real :: x(..) |
| 8 |
end subroutine |
| 9 |
subroutine takes_char(x) |
| 10 |
character(*) :: x(..) |
| 11 |
end subroutine |
| 12 |
end interface |
| 13 |
contains |
| 14 |
|
| 15 |
subroutine test_intrinsic(x) |
| 16 |
real :: x(..) |
| 17 |
call takes_real(x) |
| 18 |
end subroutine |
| 19 |
|
| 20 |
subroutine test_character_explicit_len(x, n) |
| 21 |
integer(8) :: n |
| 22 |
character(n) :: x(..) |
| 23 |
call takes_char(x) |
| 24 |
end subroutine |
| 25 |
|
| 26 |
subroutine test_character_assumed_len(x) |
| 27 |
character(*) :: x(..) |
| 28 |
call takes_char(x) |
| 29 |
end subroutine |
| 30 |
|
| 31 |
subroutine test_with_attrs(x) |
| 32 |
real, target, optional :: x(..) |
| 33 |
call takes_real(x) |
| 34 |
end subroutine |
| 35 |
|
| 36 |
subroutine test_simple_allocatable(x) |
| 37 |
real, allocatable :: x(..) |
| 38 |
end subroutine |
| 39 |
|
| 40 |
subroutine test_simple_pointer(x) |
| 41 |
real, pointer :: x(..) |
| 42 |
end subroutine |
| 43 |
|
| 44 |
subroutine test_intentout(x) |
| 45 |
real, intent(out), allocatable :: x(..) |
| 46 |
end subroutine |
| 47 |
|
| 48 |
subroutine test_assumed_length_alloc(x) |
| 49 |
character(*), allocatable :: x(..) |
| 50 |
end subroutine |
| 51 |
|
| 52 |
! CHECK-LABEL: func.func @_QMassumed_rank_testsPtest_intrinsic( |
| 53 |
! CHECK-SAME: %[[VAL_0:.*]]: !fir.box<!fir.array<*:f32>> {fir.bindc_name = "x"}) { |
| 54 |
! CHECK: %[[VAL_1:.*]] = fir.dummy_scope : !fir.dscope |
| 55 |
! CHECK: %[[VAL_2:.*]]:2 = hlfir.declare %[[VAL_0]] dummy_scope %[[VAL_1]] {uniq_name = "_QMassumed_rank_testsFtest_intrinsicEx"} : (!fir.box<!fir.array<*:f32>>, !fir.dscope) -> (!fir.box<!fir.array<*:f32>>, !fir.box<!fir.array<*:f32>>) |
| 56 |
! CHECK: fir.call @_QPtakes_real(%[[VAL_2]]#0) fastmath<contract> : (!fir.box<!fir.array<*:f32>>) -> () |
| 57 |
! CHECK: return |
| 58 |
! CHECK: } |
| 59 |
|
| 60 |
! CHECK-LABEL: func.func @_QMassumed_rank_testsPtest_character_explicit_len( |
| 61 |
! CHECK-SAME: %[[VAL_0:.*]]: !fir.box<!fir.array<*:!fir.char<1,?>>> {fir.bindc_name = "x"}, |
| 62 |
! CHECK-SAME: %[[VAL_1:.*]]: !fir.ref<i64> {fir.bindc_name = "n"}) { |
| 63 |
! CHECK: %[[VAL_2:.*]] = fir.dummy_scope : !fir.dscope |
| 64 |
! CHECK: %[[VAL_3:.*]]:2 = hlfir.declare %[[VAL_1]] dummy_scope %[[VAL_2]] {uniq_name = "_QMassumed_rank_testsFtest_character_explicit_lenEn"} : (!fir.ref<i64>, !fir.dscope) -> (!fir.ref<i64>, !fir.ref<i64>) |
| 65 |
! CHECK: %[[VAL_4:.*]] = fir.load %[[VAL_3]]#0 : !fir.ref<i64> |
| 66 |
! CHECK: %[[VAL_5:.*]] = arith.constant 0 : i64 |
| 67 |
! CHECK: %[[VAL_6:.*]] = arith.cmpi sgt, %[[VAL_4]], %[[VAL_5]] : i64 |
| 68 |
! CHECK: %[[VAL_7:.*]] = arith.select %[[VAL_6]], %[[VAL_4]], %[[VAL_5]] : i64 |
| 69 |
! CHECK: %[[VAL_8:.*]]:2 = hlfir.declare %[[VAL_0]] typeparams %[[VAL_7]] dummy_scope %[[VAL_2]] {uniq_name = "_QMassumed_rank_testsFtest_character_explicit_lenEx"} : (!fir.box<!fir.array<*:!fir.char<1,?>>>, i64, !fir.dscope) -> (!fir.box<!fir.array<*:!fir.char<1,?>>>, !fir.box<!fir.array<*:!fir.char<1,?>>>) |
| 70 |
! CHECK: fir.call @_QPtakes_char(%[[VAL_8]]#0) fastmath<contract> : (!fir.box<!fir.array<*:!fir.char<1,?>>>) -> () |
| 71 |
! CHECK: return |
| 72 |
! CHECK: } |
| 73 |
|
| 74 |
! CHECK-LABEL: func.func @_QMassumed_rank_testsPtest_character_assumed_len( |
| 75 |
! CHECK-SAME: %[[VAL_0:.*]]: !fir.box<!fir.array<*:!fir.char<1,?>>> {fir.bindc_name = "x"}) { |
| 76 |
! CHECK: %[[VAL_1:.*]] = fir.dummy_scope : !fir.dscope |
| 77 |
! CHECK: %[[VAL_2:.*]]:2 = hlfir.declare %[[VAL_0]] dummy_scope %[[VAL_1]] {uniq_name = "_QMassumed_rank_testsFtest_character_assumed_lenEx"} : (!fir.box<!fir.array<*:!fir.char<1,?>>>, !fir.dscope) -> (!fir.box<!fir.array<*:!fir.char<1,?>>>, !fir.box<!fir.array<*:!fir.char<1,?>>>) |
| 78 |
! CHECK: fir.call @_QPtakes_char(%[[VAL_2]]#0) fastmath<contract> : (!fir.box<!fir.array<*:!fir.char<1,?>>>) -> () |
| 79 |
! CHECK: return |
| 80 |
! CHECK: } |
| 81 |
|
| 82 |
! CHECK-LABEL: func.func @_QMassumed_rank_testsPtest_with_attrs( |
| 83 |
! CHECK-SAME: %[[VAL_0:.*]]: !fir.box<!fir.array<*:f32>> {fir.bindc_name = "x", fir.optional, fir.target}) { |
| 84 |
! CHECK: %[[VAL_1:.*]] = fir.dummy_scope : !fir.dscope |
| 85 |
! CHECK: %[[VAL_2:.*]]:2 = hlfir.declare %[[VAL_0]] dummy_scope %[[VAL_1]] {fortran_attrs = #fir.var_attrs<optional, target>, uniq_name = "_QMassumed_rank_testsFtest_with_attrsEx"} : (!fir.box<!fir.array<*:f32>>, !fir.dscope) -> (!fir.box<!fir.array<*:f32>>, !fir.box<!fir.array<*:f32>>) |
| 86 |
! CHECK: fir.call @_QPtakes_real(%[[VAL_2]]#0) fastmath<contract> : (!fir.box<!fir.array<*:f32>>) -> () |
| 87 |
|
| 88 |
! CHECK-LABEL: func.func @_QMassumed_rank_testsPtest_simple_allocatable( |
| 89 |
! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<!fir.box<!fir.heap<!fir.array<*:f32>>>> {fir.bindc_name = "x"}) { |
| 90 |
! CHECK: %[[VAL_1:.*]] = fir.dummy_scope : !fir.dscope |
| 91 |
! CHECK: %[[VAL_2:.*]]:2 = hlfir.declare %[[VAL_0]] dummy_scope %[[VAL_1]] {fortran_attrs = #fir.var_attrs<allocatable>, uniq_name = "_QMassumed_rank_testsFtest_simple_allocatableEx"} : (!fir.ref<!fir.box<!fir.heap<!fir.array<*:f32>>>>, !fir.dscope) -> (!fir.ref<!fir.box<!fir.heap<!fir.array<*:f32>>>>, !fir.ref<!fir.box<!fir.heap<!fir.array<*:f32>>>>) |
| 92 |
! CHECK: return |
| 93 |
! CHECK: } |
| 94 |
|
| 95 |
! CHECK-LABEL: func.func @_QMassumed_rank_testsPtest_simple_pointer( |
| 96 |
! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<!fir.box<!fir.ptr<!fir.array<*:f32>>>> {fir.bindc_name = "x"}) { |
| 97 |
! CHECK: %[[VAL_1:.*]] = fir.dummy_scope : !fir.dscope |
| 98 |
! CHECK: %[[VAL_2:.*]]:2 = hlfir.declare %[[VAL_0]] dummy_scope %[[VAL_1]] {fortran_attrs = #fir.var_attrs<pointer>, uniq_name = "_QMassumed_rank_testsFtest_simple_pointerEx"} : (!fir.ref<!fir.box<!fir.ptr<!fir.array<*:f32>>>>, !fir.dscope) -> (!fir.ref<!fir.box<!fir.ptr<!fir.array<*:f32>>>>, !fir.ref<!fir.box<!fir.ptr<!fir.array<*:f32>>>>) |
| 99 |
! CHECK: return |
| 100 |
! CHECK: } |
| 101 |
|
| 102 |
! CHECK-LABEL: func.func @_QMassumed_rank_testsPtest_intentout( |
| 103 |
! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<!fir.box<!fir.heap<!fir.array<*:f32>>>> {fir.bindc_name = "x"}) { |
| 104 |
! CHECK: %[[VAL_1:.*]] = fir.dummy_scope : !fir.dscope |
| 105 |
! CHECK: %[[VAL_2:.*]]:2 = hlfir.declare %[[VAL_0]] dummy_scope %[[VAL_1]] {fortran_attrs = #fir.var_attrs<allocatable, intent_out>, uniq_name = "_QMassumed_rank_testsFtest_intentoutEx"} : (!fir.ref<!fir.box<!fir.heap<!fir.array<*:f32>>>>, !fir.dscope) -> (!fir.ref<!fir.box<!fir.heap<!fir.array<*:f32>>>>, !fir.ref<!fir.box<!fir.heap<!fir.array<*:f32>>>>) |
| 106 |
! CHECK: %[[VAL_3:.*]] = fir.load %[[VAL_2]]#0 : !fir.ref<!fir.box<!fir.heap<!fir.array<*:f32>>>> |
| 107 |
! CHECK: %[[VAL_4:.*]] = fir.box_addr %[[VAL_3]] : (!fir.box<!fir.heap<!fir.array<*:f32>>>) -> !fir.heap<!fir.array<*:f32>> |
| 108 |
! CHECK: %[[VAL_5:.*]] = fir.convert %[[VAL_4]] : (!fir.heap<!fir.array<*:f32>>) -> i64 |
| 109 |
! CHECK: %[[VAL_6:.*]] = arith.constant 0 : i64 |
| 110 |
! CHECK: %[[VAL_7:.*]] = arith.cmpi ne, %[[VAL_5]], %[[VAL_6]] : i64 |
| 111 |
! CHECK: fir.if %[[VAL_7]] { |
| 112 |
! CHECK: %[[VAL_8:.*]] = arith.constant false |
| 113 |
! CHECK: %[[VAL_9:.*]] = fir.absent !fir.box<none> |
| 114 |
! CHECK: %[[VAL_12:.*]] = fir.convert %[[VAL_2]]#0 : (!fir.ref<!fir.box<!fir.heap<!fir.array<*:f32>>>>) -> !fir.ref<!fir.box<none>> |
| 115 |
! CHECK: %[[VAL_14:.*]] = fir.call @_FortranAAllocatableDeallocate(%[[VAL_12]], %[[VAL_8]], %[[VAL_9]], %{{.*}}, %{{.*}}) fastmath<contract> : (!fir.ref<!fir.box<none>>, i1, !fir.box<none>, !fir.ref<i8>, i32) -> i32 |
| 116 |
! CHECK: } |
| 117 |
! CHECK: return |
| 118 |
! CHECK: } |
| 119 |
|
| 120 |
! CHECK-LABEL: func.func @_QMassumed_rank_testsPtest_assumed_length_alloc( |
| 121 |
! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<!fir.box<!fir.heap<!fir.array<*:!fir.char<1,?>>>>> {fir.bindc_name = "x"}) { |
| 122 |
! CHECK: %[[VAL_1:.*]] = fir.dummy_scope : !fir.dscope |
| 123 |
! CHECK: %[[VAL_2:.*]] = fir.load %[[VAL_0]] : !fir.ref<!fir.box<!fir.heap<!fir.array<*:!fir.char<1,?>>>>> |
| 124 |
! CHECK: %[[VAL_3:.*]] = fir.box_elesize %[[VAL_2]] : (!fir.box<!fir.heap<!fir.array<*:!fir.char<1,?>>>>) -> index |
| 125 |
! CHECK: %[[VAL_4:.*]]:2 = hlfir.declare %[[VAL_0]] typeparams %[[VAL_3]] dummy_scope %[[VAL_1]] {fortran_attrs = #fir.var_attrs<allocatable>, uniq_name = "_QMassumed_rank_testsFtest_assumed_length_allocEx"} : (!fir.ref<!fir.box<!fir.heap<!fir.array<*:!fir.char<1,?>>>>>, index, !fir.dscope) -> (!fir.ref<!fir.box<!fir.heap<!fir.array<*:!fir.char<1,?>>>>>, !fir.ref<!fir.box<!fir.heap<!fir.array<*:!fir.char<1,?>>>>>) |
| 126 |
! CHECK: return |
| 127 |
! CHECK: } |
| 128 |
end module |