|
| 1 | +! RUN: bbc -emit-hlfir --polymorphic-type -o - %s -I nowhere 2>&1 | FileCheck %s |
| 2 | + |
| 3 | +module types |
| 4 | + type t1 |
| 5 | + end type t1 |
| 6 | +end module types |
| 7 | + |
| 8 | +subroutine test1 |
| 9 | + integer :: i |
| 10 | + i = inner() + 1 |
| 11 | +contains |
| 12 | + function inner() |
| 13 | + integer, allocatable :: inner |
| 14 | + end function inner |
| 15 | +end subroutine test1 |
| 16 | +! CHECK-LABEL: func.func @_QPtest1() { |
| 17 | +! CHECK: %[[VAL_0:.*]] = fir.alloca !fir.box<!fir.heap<i32>> {bindc_name = ".result"} |
| 18 | +! CHECK: %[[VAL_4:.*]]:2 = hlfir.declare %[[VAL_0]] {uniq_name = ".tmp.func_result"} : (!fir.ref<!fir.box<!fir.heap<i32>>>) -> (!fir.ref<!fir.box<!fir.heap<i32>>>, !fir.ref<!fir.box<!fir.heap<i32>>>) |
| 19 | +! CHECK: %[[VAL_5:.*]] = fir.load %[[VAL_4]]#0 : !fir.ref<!fir.box<!fir.heap<i32>>> |
| 20 | +! CHECK: %[[VAL_6:.*]] = fir.box_addr %[[VAL_5]] : (!fir.box<!fir.heap<i32>>) -> !fir.heap<i32> |
| 21 | +! CHECK: %[[VAL_7:.*]] = fir.load %[[VAL_6]] : !fir.heap<i32> |
| 22 | +! CHECK: %[[VAL_8:.*]] = arith.constant 1 : i32 |
| 23 | +! CHECK: %[[VAL_9:.*]] = arith.addi %[[VAL_7]], %[[VAL_8]] : i32 |
| 24 | + |
| 25 | +subroutine test2 |
| 26 | + character(len=:), allocatable :: c |
| 27 | + c = inner() |
| 28 | +contains |
| 29 | + function inner() |
| 30 | + character(len=:), allocatable :: inner |
| 31 | + end function inner |
| 32 | +end subroutine test2 |
| 33 | +! CHECK-LABEL: func.func @_QPtest2() { |
| 34 | +! CHECK: %[[VAL_7:.*]]:2 = hlfir.declare %{{.*}} {uniq_name = ".tmp.func_result"} : (!fir.ref<!fir.box<!fir.heap<!fir.char<1,?>>>>) -> (!fir.ref<!fir.box<!fir.heap<!fir.char<1,?>>>>, !fir.ref<!fir.box<!fir.heap<!fir.char<1,?>>>>) |
| 35 | +! CHECK: %[[VAL_8:.*]] = fir.load %[[VAL_7]]#0 : !fir.ref<!fir.box<!fir.heap<!fir.char<1,?>>>> |
| 36 | +! CHECK: %[[VAL_9:.*]] = fir.box_addr %[[VAL_8]] : (!fir.box<!fir.heap<!fir.char<1,?>>>) -> !fir.heap<!fir.char<1,?>> |
| 37 | +! CHECK: %[[VAL_10:.*]] = fir.load %[[VAL_7]]#0 : !fir.ref<!fir.box<!fir.heap<!fir.char<1,?>>>> |
| 38 | +! CHECK: %[[VAL_11:.*]] = fir.box_elesize %[[VAL_10]] : (!fir.box<!fir.heap<!fir.char<1,?>>>) -> index |
| 39 | +! CHECK: %[[VAL_12:.*]] = fir.emboxchar %[[VAL_9]], %[[VAL_11]] : (!fir.heap<!fir.char<1,?>>, index) -> !fir.boxchar<1> |
| 40 | +! CHECK: %[[VAL_13:.*]] = arith.constant false |
| 41 | +! CHECK: %[[VAL_14:.*]] = hlfir.as_expr %[[VAL_12]] move %[[VAL_13]] : (!fir.boxchar<1>, i1) -> !hlfir.expr<!fir.char<1,?>> |
| 42 | +! CHECK: hlfir.assign %[[VAL_14]] to %{{.*}}#0 realloc : !hlfir.expr<!fir.char<1,?>>, !fir.ref<!fir.box<!fir.heap<!fir.char<1,?>>>> |
| 43 | + |
| 44 | +subroutine test3 |
| 45 | + character(len=:), allocatable :: c |
| 46 | + c = inner() |
| 47 | +contains |
| 48 | + function inner() |
| 49 | + character(len=3), allocatable :: inner |
| 50 | + end function inner |
| 51 | +end subroutine test3 |
| 52 | +! CHECK-LABEL: func.func @_QPtest3() { |
| 53 | +! CHECK: %[[VAL_13:.*]]:2 = hlfir.declare %{{.*}} typeparams %{{.*}} {uniq_name = ".tmp.func_result"} : (!fir.ref<!fir.box<!fir.heap<!fir.char<1,3>>>>, index) -> (!fir.ref<!fir.box<!fir.heap<!fir.char<1,3>>>>, !fir.ref<!fir.box<!fir.heap<!fir.char<1,3>>>>) |
| 54 | +! CHECK: %[[VAL_14:.*]] = fir.load %[[VAL_13]]#0 : !fir.ref<!fir.box<!fir.heap<!fir.char<1,3>>>> |
| 55 | +! CHECK: %[[VAL_15:.*]] = fir.box_addr %[[VAL_14]] : (!fir.box<!fir.heap<!fir.char<1,3>>>) -> !fir.heap<!fir.char<1,3>> |
| 56 | +! CHECK: %[[VAL_16:.*]] = arith.constant false |
| 57 | +! CHECK: %[[VAL_17:.*]] = hlfir.as_expr %[[VAL_15]] move %[[VAL_16]] : (!fir.heap<!fir.char<1,3>>, i1) -> !hlfir.expr<!fir.char<1,3>> |
| 58 | +! CHECK: hlfir.assign %[[VAL_17]] to %{{.*}}#0 realloc : !hlfir.expr<!fir.char<1,3>>, !fir.ref<!fir.box<!fir.heap<!fir.char<1,?>>>> |
| 59 | + |
| 60 | +subroutine test4 |
| 61 | + class(*), allocatable :: p |
| 62 | + p = inner() |
| 63 | +contains |
| 64 | + function inner() |
| 65 | + class(*), allocatable :: inner |
| 66 | + end function inner |
| 67 | +end subroutine test4 |
| 68 | +! CHECK-LABEL: func.func @_QPtest4() { |
| 69 | +! CHECK: %[[VAL_6:.*]]:2 = hlfir.declare %{{.*}} {uniq_name = ".tmp.func_result"} : (!fir.ref<!fir.class<!fir.heap<none>>>) -> (!fir.ref<!fir.class<!fir.heap<none>>>, !fir.ref<!fir.class<!fir.heap<none>>>) |
| 70 | +! CHECK: %[[VAL_7:.*]] = fir.load %[[VAL_6]]#0 : !fir.ref<!fir.class<!fir.heap<none>>> |
| 71 | +! CHECK: %[[VAL_8:.*]] = arith.constant false |
| 72 | +! CHECK: %[[VAL_9:.*]] = hlfir.as_expr %[[VAL_7]] move %[[VAL_8]] : (!fir.class<!fir.heap<none>>, i1) -> !hlfir.expr<none?> |
| 73 | +! CHECK: hlfir.assign %[[VAL_9]] to %{{.*}}#0 realloc : !hlfir.expr<none?>, !fir.ref<!fir.class<!fir.heap<none>>> |
| 74 | + |
| 75 | +subroutine test5 |
| 76 | + use types |
| 77 | + type(t1) :: r |
| 78 | + r = inner() |
| 79 | +contains |
| 80 | + function inner() |
| 81 | + type(t1) :: inner |
| 82 | + end function inner |
| 83 | +end subroutine test5 |
| 84 | +! CHECK-LABEL: func.func @_QPtest5() { |
| 85 | +! CHECK: %[[VAL_4:.*]]:2 = hlfir.declare %{{.*}} {uniq_name = ".tmp.func_result"} : (!fir.ref<!fir.type<_QMtypesTt1>>) -> (!fir.ref<!fir.type<_QMtypesTt1>>, !fir.ref<!fir.type<_QMtypesTt1>>) |
| 86 | +! CHECK: %[[VAL_5:.*]] = arith.constant false |
| 87 | +! CHECK: %[[VAL_6:.*]] = hlfir.as_expr %[[VAL_4]]#0 move %[[VAL_5]] : (!fir.ref<!fir.type<_QMtypesTt1>>, i1) -> !hlfir.expr<!fir.type<_QMtypesTt1>> |
| 88 | +! CHECK: hlfir.assign %[[VAL_6]] to %{{.*}}#0 : !hlfir.expr<!fir.type<_QMtypesTt1>>, !fir.ref<!fir.type<_QMtypesTt1>> |
| 89 | + |
| 90 | +subroutine test6(x) |
| 91 | + character(len=:), allocatable :: c(:) |
| 92 | + integer :: x(:) |
| 93 | + c = inner(x) |
| 94 | +contains |
| 95 | + elemental function inner(x) |
| 96 | + integer, intent(in) :: x |
| 97 | + character(len=3) :: inner |
| 98 | + end function inner |
| 99 | +end subroutine test6 |
| 100 | +! CHECK-LABEL: func.func @_QPtest6( |
| 101 | +! CHECK: %[[VAL_14:.*]] = hlfir.elemental |
| 102 | +! CHECK: %[[VAL_24:.*]]:2 = hlfir.declare %{{.*}} typeparams %{{.*}} {uniq_name = ".tmp.func_result"} : (!fir.ref<!fir.char<1,3>>, index) -> (!fir.ref<!fir.char<1,3>>, !fir.ref<!fir.char<1,3>>) |
| 103 | +! CHECK: %[[VAL_25:.*]] = arith.constant false |
| 104 | +! CHECK: %[[VAL_26:.*]] = hlfir.as_expr %[[VAL_24]]#0 move %[[VAL_25]] : (!fir.ref<!fir.char<1,3>>, i1) -> !hlfir.expr<!fir.char<1,3>> |
| 105 | +! CHECK: hlfir.yield_element %[[VAL_26]] : !hlfir.expr<!fir.char<1,3>> |
| 106 | + |
| 107 | +subroutine test7(x) |
| 108 | + use types |
| 109 | + integer :: x(:) |
| 110 | + class(*), allocatable :: p(:) |
| 111 | + p = inner(x) |
| 112 | +contains |
| 113 | + elemental function inner(x) |
| 114 | + integer, intent(in) :: x |
| 115 | + type(t1) :: inner |
| 116 | + end function inner |
| 117 | +end subroutine test7 |
| 118 | +! CHECK-LABEL: func.func @_QPtest7( |
| 119 | +! CHECK: %[[VAL_12:.*]] = hlfir.elemental |
| 120 | +! CHECK: %[[VAL_16:.*]]:2 = hlfir.declare %{{.*}} {uniq_name = ".tmp.func_result"} : (!fir.ref<!fir.type<_QMtypesTt1>>) -> (!fir.ref<!fir.type<_QMtypesTt1>>, !fir.ref<!fir.type<_QMtypesTt1>>) |
| 121 | +! CHECK: %[[VAL_17:.*]] = arith.constant false |
| 122 | +! CHECK: %[[VAL_18:.*]] = hlfir.as_expr %[[VAL_16]]#0 move %[[VAL_17]] : (!fir.ref<!fir.type<_QMtypesTt1>>, i1) -> !hlfir.expr<!fir.type<_QMtypesTt1>> |
| 123 | +! CHECK: hlfir.yield_element %[[VAL_18]] : !hlfir.expr<!fir.type<_QMtypesTt1>> |
| 124 | + |
| 125 | +subroutine test8 |
| 126 | + if (associated(inner())) STOP 1 |
| 127 | +contains |
| 128 | + function inner() |
| 129 | + real, pointer :: inner |
| 130 | + end function inner |
| 131 | +end subroutine test8 |
| 132 | +! CHECK-LABEL: func.func @_QPtest8() { |
| 133 | +! CHECK: %[[VAL_2:.*]]:2 = hlfir.declare %{{.*}} {uniq_name = ".tmp.func_result"} : (!fir.ref<!fir.box<!fir.ptr<f32>>>) -> (!fir.ref<!fir.box<!fir.ptr<f32>>>, !fir.ref<!fir.box<!fir.ptr<f32>>>) |
| 134 | +! CHECK: %[[VAL_3:.*]] = fir.load %[[VAL_2]]#1 : !fir.ref<!fir.box<!fir.ptr<f32>>> |
| 135 | +! CHECK: %[[VAL_4:.*]] = fir.box_addr %[[VAL_3]] : (!fir.box<!fir.ptr<f32>>) -> !fir.ptr<f32> |
0 commit comments