[flang-commits] [flang] 5315ca6 - [flang][NFC] Add select type test to check correct ordering
Valentin Clement via flang-commits
flang-commits at lists.llvm.org
Fri Apr 7 14:19:55 PDT 2023
Author: Valentin Clement
Date: 2023-04-07T14:19:48-07:00
New Revision: 5315ca696169ae015b5aa56ab6c27aca21d633f7
URL: https://github.com/llvm/llvm-project/commit/5315ca696169ae015b5aa56ab6c27aca21d633f7
DIFF: https://github.com/llvm/llvm-project/commit/5315ca696169ae015b5aa56ab6c27aca21d633f7.diff
LOG: [flang][NFC] Add select type test to check correct ordering
Somehow this test has been left behind in my sandbox. This
patch adds a lowering test for fir.select_type operation and
makes sure the dynamic type comaparison is done in the right
order when we have multiple CLASS IS type guard statement
for types that are linked.
This should have been posted with D138280.
Reviewed By: PeteSteinfeld
Differential Revision: https://reviews.llvm.org/D147807
Added:
flang/test/Lower/select-type-2.f90
Modified:
Removed:
################################################################################
diff --git a/flang/test/Lower/select-type-2.f90 b/flang/test/Lower/select-type-2.f90
new file mode 100644
index 000000000000..902181b8bfb6
--- /dev/null
+++ b/flang/test/Lower/select-type-2.f90
@@ -0,0 +1,55 @@
+! RUN: bbc -polymorphic-type -emit-fir %s -o - | fir-opt --fir-polymorphic-op | FileCheck %s
+module select_type_2
+ type p1
+ integer :: a
+ integer :: b
+ end type
+
+ type, extends(p1) :: p2
+ integer :: c
+ end type
+
+ type, extends(p2) :: p3
+ integer :: d
+ end type
+
+contains
+
+ subroutine select_type1(a)
+ class(p1), intent(in) :: a
+
+ select type (a)
+ class is (p1)
+ print*, 'class is p1'
+ class is (p3)
+ print*, 'class is p3'
+ class default
+ print*,'default'
+ end select
+ end subroutine
+
+! CHECK-LABEL: func.func @_QMselect_type_2Pselect_type1(
+! CHECK-SAME: %[[ARG0:.*]]: !fir.class<!fir.type<_QMselect_type_2Tp1{a:i32,b:i32}>> {fir.bindc_name = "a"}) {
+! CHECK: %[[TDESC_P3_ADDR:.*]] = fir.address_of(@_QMselect_type_2E.dt.p3) : !fir.ref<!fir.type<{{.*}}>>
+! CHECK: %[[TDESC_P3_CONV:.*]] = fir.convert %[[TDESC_P3_ADDR]] : (!fir.ref<!fir.type<{{.*}}>>) -> !fir.ref<none>
+! CHECK: %[[BOX_NONE:.*]] = fir.convert %[[ARG0]] : (!fir.class<!fir.type<_QMselect_type_2Tp1{a:i32,b:i32}>>) -> !fir.box<none>
+! CHECK: %[[CLASS_IS_CMP:.*]] = fir.call @_FortranAClassIs(%[[BOX_NONE]], %[[TDESC_P3_CONV]]) : (!fir.box<none>, !fir.ref<none>) -> i1
+! CHECK: cf.cond_br %[[CLASS_IS_CMP]], ^[[CLASS_IS_P3_BLK:.*]], ^[[NOT_CLASS_IS_P3_BLK:.*]]
+! CHECK: ^bb[[NOT_CLASS_IS_P1:[0-9]]]:
+! CHECK: cf.br ^bb[[DEFAULT_BLK:[0-9]]]
+! CHECK: ^bb[[CLASS_IS_P1:[0-9]]]:
+! CHECK: cf.br ^bb[[END_SELECT_BLK:[0-9]]]
+! CHECK: ^[[NOT_CLASS_IS_P3_BLK]]:
+! CHECK: %[[TDESC_P1_ADDR:.*]] = fir.address_of(@_QMselect_type_2E.dt.p1) : !fir.ref<!fir.type<{{.*}}>>
+! CHECK: %[[TDESC_P1_CONV:.*]] = fir.convert %[[TDESC_P1_ADDR]] : (!fir.ref<!fir.type<{{.*}}>>) -> !fir.ref<none>
+! CHECK: %[[BOX_NONE:.*]] = fir.convert %[[ARG0]] : (!fir.class<!fir.type<_QMselect_type_2Tp1{a:i32,b:i32}>>) -> !fir.box<none>
+! CHECK: %[[CLASS_IS_CMP:.*]] = fir.call @_FortranAClassIs(%[[BOX_NONE]], %[[TDESC_P1_CONV]]) : (!fir.box<none>, !fir.ref<none>) -> i1
+! CHECK: cf.cond_br %[[CLASS_IS_CMP]], ^bb[[CLASS_IS_P1]], ^bb[[NOT_CLASS_IS_P1]]
+! CHECK: ^[[CLASS_IS_P3_BLK]]:
+! CHECK: cf.br ^bb[[END_SELECT_BLK]]
+! CHECK: ^bb[[DEFAULT_BLK]]:
+! CHECK: cf.br ^bb[[END_SELECT_BLK]]
+! CHECK: ^bb[[END_SELECT_BLK]]:
+! CHECK: return
+
+ end module
More information about the flang-commits
mailing list