Index: flang/lib/Lower/ConvertExprToHLFIR.cpp =================================================================== --- flang/lib/Lower/ConvertExprToHLFIR.cpp +++ flang/lib/Lower/ConvertExprToHLFIR.cpp @@ -1525,8 +1525,11 @@ // Elemental expression. mlir::Type elementType; if constexpr (R::category == Fortran::common::TypeCategory::Derived) { - elementType = Fortran::lower::translateDerivedTypeToFIRType( - getConverter(), op.derived().GetType().GetDerivedTypeSpec()); + if (op.derived().GetType().IsUnlimitedPolymorphic()) + elementType = mlir::NoneType::get(builder.getContext()); + else + elementType = Fortran::lower::translateDerivedTypeToFIRType( + getConverter(), op.derived().GetType().GetDerivedTypeSpec()); } else { elementType = Fortran::lower::getFIRType(builder.getContext(), R::category, R::kind, Index: flang/test/Lower/HLFIR/elemental-array-ops.f90 =================================================================== --- flang/test/Lower/HLFIR/elemental-array-ops.f90 +++ flang/test/Lower/HLFIR/elemental-array-ops.f90 @@ -238,3 +238,27 @@ ! CHECK: hlfir.destroy %[[VAL_7]] : !hlfir.expr?> ! CHECK: return ! CHECK: } + +subroutine unlimited_polymorphic_parenthesis(x, y) + class(*), allocatable :: x(:) + class(*), intent(in) :: y(:) + x = (y) +end subroutine unlimited_polymorphic_parenthesis +! CHECK-LABEL: func.func @_QPunlimited_polymorphic_parenthesis( +! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref>>> {fir.bindc_name = "x"}, +! CHECK-SAME: %[[VAL_1:.*]]: !fir.class> {fir.bindc_name = "y"}) { +! CHECK: %[[VAL_2:.*]]:2 = hlfir.declare %[[VAL_0]] {fortran_attrs = #fir.var_attrs, uniq_name = "_QFunlimited_polymorphic_parenthesisEx"} : (!fir.ref>>>) -> (!fir.ref>>>, !fir.ref>>>) +! CHECK: %[[VAL_3:.*]]:2 = hlfir.declare %[[VAL_1]] {fortran_attrs = #fir.var_attrs, uniq_name = "_QFunlimited_polymorphic_parenthesisEy"} : (!fir.class>) -> (!fir.class>, !fir.class>) +! CHECK: %[[VAL_4:.*]] = arith.constant 0 : index +! CHECK: %[[VAL_5:.*]]:3 = fir.box_dims %[[VAL_3]]#0, %[[VAL_4]] : (!fir.class>, index) -> (index, index, index) +! CHECK: %[[VAL_6:.*]] = fir.shape %[[VAL_5]]#1 : (index) -> !fir.shape<1> +! CHECK: %[[VAL_7:.*]] = hlfir.elemental %[[VAL_6]] mold %[[VAL_3]]#0 unordered : (!fir.shape<1>, !fir.class>) -> !hlfir.expr { +! CHECK: ^bb0(%[[VAL_8:.*]]: index): +! CHECK: %[[VAL_9:.*]] = hlfir.designate %[[VAL_3]]#0 (%[[VAL_8]]) : (!fir.class>, index) -> !fir.class +! CHECK: %[[VAL_10:.*]] = hlfir.as_expr %[[VAL_9]] : (!fir.class) -> !hlfir.expr +! CHECK: hlfir.yield_element %[[VAL_10]] : !hlfir.expr +! CHECK: } +! CHECK: hlfir.assign %[[VAL_7]] to %[[VAL_2]]#0 realloc : !hlfir.expr, !fir.ref>>> +! CHECK: hlfir.destroy %[[VAL_7]] : !hlfir.expr +! CHECK: return +! CHECK: }