diff --git a/flang/lib/Lower/Bridge.cpp b/flang/lib/Lower/Bridge.cpp --- a/flang/lib/Lower/Bridge.cpp +++ b/flang/lib/Lower/Bridge.cpp @@ -2203,9 +2203,8 @@ const auto &s = std::get(selectTypeStmt->t); if (const auto *v = std::get_if(&s.u)) selector = genExprBox(loc, *Fortran::semantics::GetExpr(*v), stmtCtx); - else - fir::emitFatalError( - loc, "selector with expr not expected in select type statement"); + else if (const auto *e = std::get_if(&s.u)) + selector = genExprBox(loc, *Fortran::semantics::GetExpr(*e), stmtCtx); // Going through the controlSuccessor first to create the // fir.select_type operation. diff --git a/flang/test/Lower/select-type.f90 b/flang/test/Lower/select-type.f90 --- a/flang/test/Lower/select-type.f90 +++ b/flang/test/Lower/select-type.f90 @@ -19,11 +19,25 @@ integer :: d end type + type :: p5 + integer :: a + contains + procedure :: negate + generic :: operator(-) => negate + end type + contains function get_class() class(p1), pointer :: get_class end function + + function negate(this) + class(p5), intent(in) :: this + class(p5), allocatable :: negate + allocate(negate, source=this) + negate%a = -this%a + end function subroutine select_type1(a) class(p1), intent(in) :: a @@ -772,7 +786,24 @@ ! Just makes sure the example can be lowered. ! CHECK-LABEL: func.func @_QMselect_type_lower_testPselect_type14 - + + subroutine select_type15(a) + class(p5) :: a + + select type(x => -a) + type is (p5) + print*, x%a + end select + end subroutine + +! CHECK-LABEL: func.func @_QMselect_type_lower_testPselect_type15( +! CHECK-SAME: %[[ARG0:.*]]: !fir.class> {fir.bindc_name = "a"}) { +! CHECK: %[[RES:.*]] = fir.alloca !fir.class>> {bindc_name = ".result"} +! CHECK: %[[TMP_RES:.*]] = fir.dispatch "negate"(%[[ARG0]] : !fir.class>) (%[[ARG0]] : !fir.class>) -> !fir.class>> {pass_arg_pos = 0 : i32} +! CHECK: fir.save_result %[[TMP_RES]] to %[[RES]] : !fir.class>>, !fir.ref>>> +! CHECK: %[[LOAD_RES:.*]] = fir.load %[[RES]] : !fir.ref>>> +! CHECK: fir.select_type %[[LOAD_RES]] : !fir.class>> [#fir.type_is>, ^bb1, unit, ^bb2] + end module program test_select_type