|
| 1 | +! RUN: bbc -polymorphic-type -emit-fir %s -o - | FileCheck %s |
| 2 | + |
| 3 | +module select_type_lower_test |
| 4 | + type p1 |
| 5 | + integer :: a |
| 6 | + integer :: b |
| 7 | + end type |
| 8 | + |
| 9 | + type, extends(p1) :: p2 |
| 10 | + integer :: c |
| 11 | + end type |
| 12 | + |
| 13 | + type, extends(p1) :: p3(k) |
| 14 | + integer, kind :: k |
| 15 | + real(k) :: r |
| 16 | + end type |
| 17 | + |
| 18 | +contains |
| 19 | + |
| 20 | + function get_class() |
| 21 | + class(p1), pointer :: get_class |
| 22 | + end function |
| 23 | + |
| 24 | + subroutine select_type1(a) |
| 25 | + class(p1), intent(in) :: a |
| 26 | + |
| 27 | + select type (a) |
| 28 | + type is (p1) |
| 29 | + print*, 'type is p1' |
| 30 | + class is (p1) |
| 31 | + print*, 'class is p1' |
| 32 | + class is (p2) |
| 33 | + print*, 'class is p2', a%c |
| 34 | + class default |
| 35 | + print*,'default' |
| 36 | + end select |
| 37 | + end subroutine |
| 38 | + |
| 39 | +! CHECK-LABEL: func.func @_QMselect_type_lower_testPselect_type1( |
| 40 | +! CHECK-SAME: %[[ARG0:.*]]: !fir.class<!fir.type<_QMselect_type_lower_testTp1{a:i32,b:i32}>> {fir.bindc_name = "a"}) |
| 41 | + |
| 42 | +! CHECK: fir.select_type %[[ARG0]] : !fir.class<!fir.type<_QMselect_type_lower_testTp1{a:i32,b:i32}>> |
| 43 | +! CHECK-SAME: [#fir.type_is<!fir.type<_QMselect_type_lower_testTp1{a:i32,b:i32}>>, ^[[TYPE_IS_BLK:.*]], #fir.class_is<!fir.type<_QMselect_type_lower_testTp1{a:i32,b:i32}>>, ^[[CLASS_IS_P1_BLK:.*]], #fir.class_is<!fir.type<_QMselect_type_lower_testTp2{a:i32,b:i32,c:i32}>>, ^[[CLASS_IS_P2_BLK:.*]], unit, ^[[DEFAULT_BLOCK:.*]]] |
| 44 | +! CHECK: ^[[TYPE_IS_BLK]] |
| 45 | +! CHECK: ^[[CLASS_IS_P1_BLK]] |
| 46 | +! CHECK: ^[[CLASS_IS_P2_BLK]] |
| 47 | +! CHECK: %[[P2:.*]] = fir.convert %[[ARG0:.*]] : (!fir.class<!fir.type<_QMselect_type_lower_testTp1{a:i32,b:i32}>>) -> !fir.class<!fir.type<_QMselect_type_lower_testTp2{a:i32,b:i32,c:i32}>> |
| 48 | +! CHECK: %[[FIELD:.*]] = fir.field_index c, !fir.type<_QMselect_type_lower_testTp2{a:i32,b:i32,c:i32}> |
| 49 | +! CHECK: %{{.*}} = fir.coordinate_of %[[P2]], %[[FIELD]] : (!fir.class<!fir.type<_QMselect_type_lower_testTp2{a:i32,b:i32,c:i32}>>, !fir.field) -> !fir.ref<i32> |
| 50 | +! CHECK: ^[[DEFAULT_BLOCK]] |
| 51 | + |
| 52 | + subroutine select_type2() |
| 53 | + select type (a => get_class()) |
| 54 | + type is (p1) |
| 55 | + print*, 'type is p1' |
| 56 | + class is (p1) |
| 57 | + print*, 'class is p1' |
| 58 | + class default |
| 59 | + print*,'default' |
| 60 | + end select |
| 61 | + end subroutine |
| 62 | + |
| 63 | +! CHECK-LABEL: func.func @_QMselect_type_lower_testPselect_type2() |
| 64 | +! CHECK: %[[RESULT:.*]] = fir.alloca !fir.class<!fir.ptr<!fir.type<_QMselect_type_lower_testTp1{a:i32,b:i32}>>> {bindc_name = ".result"} |
| 65 | +! CHECK: %[[FCTCALL:.*]] = fir.call @_QMselect_type_lower_testPget_class() : () -> !fir.class<!fir.ptr<!fir.type<_QMselect_type_lower_testTp1{a:i32,b:i32}>>> |
| 66 | +! CHECK: fir.save_result %[[FCTCALL]] to %[[RESULT]] : !fir.class<!fir.ptr<!fir.type<_QMselect_type_lower_testTp1{a:i32,b:i32}>>>, !fir.ref<!fir.class<!fir.ptr<!fir.type<_QMselect_type_lower_testTp1{a:i32,b:i32}>>>> |
| 67 | +! CHECK: %[[SELECTOR:.*]] = fir.load %[[RESULT]] : !fir.ref<!fir.class<!fir.ptr<!fir.type<_QMselect_type_lower_testTp1{a:i32,b:i32}>>>> |
| 68 | +! CHECK: fir.select_type %[[SELECTOR]] : !fir.class<!fir.ptr<!fir.type<_QMselect_type_lower_testTp1{a:i32,b:i32}>>> |
| 69 | +! CHECK-SAME: [#fir.type_is<!fir.type<_QMselect_type_lower_testTp1{a:i32,b:i32}>>, ^[[TYPE_IS_BLK:.*]], #fir.class_is<!fir.type<_QMselect_type_lower_testTp1{a:i32,b:i32}>>, ^[[CLASS_IS_BLK:.*]], unit, ^[[DEFAULT_BLK:.*]]] |
| 70 | +! CHECK: ^[[TYPE_IS_BLK]] |
| 71 | +! CHECK: ^[[CLASS_IS_BLK]] |
| 72 | +! CHECK: ^[[DEFAULT_BLK]] |
| 73 | + |
| 74 | + subroutine select_type3(a) |
| 75 | + class(p1), pointer, intent(in) :: a(:) |
| 76 | + |
| 77 | + select type (x => a(1)) |
| 78 | + type is (p1) |
| 79 | + print*, 'type is p1' |
| 80 | + class is (p1) |
| 81 | + print*, 'class is p1' |
| 82 | + class default |
| 83 | + print*,'default' |
| 84 | + end select |
| 85 | + end subroutine |
| 86 | + |
| 87 | +! CHECK-LABEL: func.func @_QMselect_type_lower_testPselect_type3( |
| 88 | +! CHECK-SAME: %[[ARG0:.*]]: !fir.ref<!fir.class<!fir.ptr<!fir.array<?x!fir.type<_QMselect_type_lower_testTp1{a:i32,b:i32}>>>>> {fir.bindc_name = "a"}) |
| 89 | +! CHECK: %[[ARG0_LOAD:.*]] = fir.load %[[ARG0]] : !fir.ref<!fir.class<!fir.ptr<!fir.array<?x!fir.type<_QMselect_type_lower_testTp1{a:i32,b:i32}>>>>> |
| 90 | +! CHECK: %[[COORD:.*]] = fir.coordinate_of %[[ARG0_LOAD]], %{{.*}} : (!fir.class<!fir.ptr<!fir.array<?x!fir.type<_QMselect_type_lower_testTp1{a:i32,b:i32}>>>>, i64) -> !fir.ref<!fir.type<_QMselect_type_lower_testTp1{a:i32,b:i32}>> |
| 91 | +! CHECK: %[[TDESC:.*]] = fir.box_tdesc %[[ARG0_LOAD]] : (!fir.class<!fir.ptr<!fir.array<?x!fir.type<_QMselect_type_lower_testTp1{a:i32,b:i32}>>>>) -> !fir.tdesc<none> |
| 92 | +! CHECK: %[[SELECTOR:.*]] = fir.embox %[[COORD]] tdesc %[[TDESC]] : (!fir.ref<!fir.type<_QMselect_type_lower_testTp1{a:i32,b:i32}>>, !fir.tdesc<none>) -> !fir.class<!fir.type<_QMselect_type_lower_testTp1{a:i32,b:i32}>> |
| 93 | +! CHECK: fir.select_type %[[SELECTOR]] : !fir.class<!fir.type<_QMselect_type_lower_testTp1{a:i32,b:i32}>> |
| 94 | +! CHECK-SAME: [#fir.type_is<!fir.type<_QMselect_type_lower_testTp1{a:i32,b:i32}>>, ^[[TYPE_IS_BLK:.*]], #fir.class_is<!fir.type<_QMselect_type_lower_testTp1{a:i32,b:i32}>>, ^[[CLASS_IS_BLK:.*]], unit, ^[[DEFAULT_BLK:.*]]] |
| 95 | +! CHECK: ^[[TYPE_IS_BLK]] |
| 96 | +! CHECK: ^[[CLASS_IS_BLK]] |
| 97 | +! CHECK: ^[[DEFAULT_BLK]] |
| 98 | + |
| 99 | + subroutine select_type4(a) |
| 100 | + class(p1), intent(in) :: a |
| 101 | + select type(a) |
| 102 | + type is(p3(8)) |
| 103 | + print*, 'type is p3(8)' |
| 104 | + type is(p3(4)) |
| 105 | + print*, 'type is p3(4)' |
| 106 | + class is (p1) |
| 107 | + print*, 'class is p1' |
| 108 | + end select |
| 109 | + end subroutine |
| 110 | + |
| 111 | +! CHECK-LABEL: func.func @_QMselect_type_lower_testPselect_type4( |
| 112 | +! CHECK-SAME: %[[ARG0:.*]]: !fir.class<!fir.type<_QMselect_type_lower_testTp1{a:i32,b:i32}>> {fir.bindc_name = "a"}) |
| 113 | +! CHECK: fir.select_type %[[ARG0]] : !fir.class<!fir.type<_QMselect_type_lower_testTp1{a:i32,b:i32}>> |
| 114 | +! CHECK-SAME: [#fir.type_is<!fir.type<_QMselect_type_lower_testTp3K8{a:i32,b:i32,r:f64}>>, ^[[P3_8:.*]], #fir.type_is<!fir.type<_QMselect_type_lower_testTp3K4{a:i32,b:i32,r:f32}>>, ^[[P3_4:.*]], #fir.class_is<!fir.type<_QMselect_type_lower_testTp1{a:i32,b:i32}>>, ^[[P1:.*]], unit, ^[[EXIT:.*]]] |
| 115 | +! CHECK: ^[[P3_8]] |
| 116 | +! CHECK: ^[[P3_4]] |
| 117 | +! CHECK: ^[[P1]] |
| 118 | +! CHECK: ^[[EXIT]] |
| 119 | + |
| 120 | + subroutine select_type5(a) |
| 121 | + class(*), intent(in) :: a |
| 122 | + |
| 123 | + select type (x => a) |
| 124 | + type is (integer(1)) |
| 125 | + print*, 'type is integer(1)' |
| 126 | + type is (integer(4)) |
| 127 | + print*, 'type is integer(4)' |
| 128 | + type is (real(4)) |
| 129 | + print*, 'type is real' |
| 130 | + type is (logical) |
| 131 | + print*, 'type is logical' |
| 132 | + class default |
| 133 | + print*,'default' |
| 134 | + end select |
| 135 | + end subroutine |
| 136 | + |
| 137 | +! CHECK-LABEL: func.func @_QMselect_type_lower_testPselect_type5( |
| 138 | +! CHECK-SAME: %[[ARG0:.*]]: !fir.class<none> {fir.bindc_name = "a"}) |
| 139 | +! CHECK: fir.select_type %[[ARG0]] : !fir.class<none> |
| 140 | +! CHECK-SAME: [#fir.type_is<i8>, ^[[I8_BLK:.*]], #fir.type_is<i32>, ^[[I32_BLK:.*]], #fir.type_is<f32>, ^[[F32_BLK:.*]], #fir.type_is<!fir.logical<4>>, ^[[LOG_BLK:.*]], unit, ^[[DEFAULT:.*]]] |
| 141 | +! CHECK: ^[[I8_BLK]] |
| 142 | +! CHECK: ^[[I32_BLK]] |
| 143 | +! CHECK: ^[[F32_BLK]] |
| 144 | +! CHECK: ^[[LOG_BLK]] |
| 145 | +! CHECK: ^[[DEFAULT_BLOCK]] |
| 146 | + |
| 147 | + |
| 148 | + subroutine select_type6(a) |
| 149 | + class(*), intent(out) :: a |
| 150 | + |
| 151 | + select type(a) |
| 152 | + type is (integer) |
| 153 | + a = 100 |
| 154 | + type is (real) |
| 155 | + a = 2.0 |
| 156 | + class default |
| 157 | + stop 'error' |
| 158 | + end select |
| 159 | + end subroutine |
| 160 | + |
| 161 | +! CHECK-LABEL: func.func @_QMselect_type_lower_testPselect_type6( |
| 162 | +! CHECK-SAME: %[[ARG0:.*]]: !fir.class<none> {fir.bindc_name = "a"}) |
| 163 | + |
| 164 | +! CHECK: fir.select_type %[[ARG0]] : !fir.class<none> [#fir.type_is<i32>, ^[[INT_BLK:.*]], #fir.type_is<f32>, ^[[REAL_BLK:.*]], unit, ^[[DEFAULT_BLK:.*]]] |
| 165 | +! CHECK: ^[[INT_BLK]] |
| 166 | +! CHECK: %[[BOX_ADDR:.*]] = fir.box_addr %[[ARG0]] : (!fir.class<none>) -> !fir.ref<i32> |
| 167 | +! CHECK: %[[C100:.*]] = arith.constant 100 : i32 |
| 168 | +! CHECK: fir.store %[[C100]] to %[[BOX_ADDR]] : !fir.ref<i32> |
| 169 | + |
| 170 | +! CHECK: ^[[REAL_BLK]]: // pred: ^bb0 |
| 171 | +! CHECK: %[[BOX_ADDR:.*]] = fir.box_addr %[[ARG0]] : (!fir.class<none>) -> !fir.ref<f32> |
| 172 | +! CHECK: %[[C2:.*]] = arith.constant 2.000000e+00 : f32 |
| 173 | +! CHECK: fir.store %[[C2]] to %[[BOX_ADDR]] : !fir.ref<f32> |
| 174 | + |
| 175 | +end module |
| 176 | + |
| 177 | + |
0 commit comments