diff --git a/flang/lib/Optimizer/Dialect/FIRType.cpp b/flang/lib/Optimizer/Dialect/FIRType.cpp --- a/flang/lib/Optimizer/Dialect/FIRType.cpp +++ b/flang/lib/Optimizer/Dialect/FIRType.cpp @@ -511,7 +511,8 @@ mlir::Type eleTy) { if (eleTy.isa()) + mlir::FloatType, fir::CharacterType, fir::LogicalType, + fir::ComplexType, mlir::ComplexType>()) return mlir::success(); return emitError() << "invalid element type\n"; } diff --git a/flang/test/Fir/invalid-types.fir b/flang/test/Fir/invalid-types.fir --- a/flang/test/Fir/invalid-types.fir +++ b/flang/test/Fir/invalid-types.fir @@ -166,4 +166,4 @@ // ----- // expected-error@+1 {{invalid element type}} -func.func private @upe() -> !fir.class> +func.func private @upe() -> !fir.class> diff --git a/flang/test/Lower/polymorphic.f90 b/flang/test/Lower/polymorphic.f90 --- a/flang/test/Lower/polymorphic.f90 +++ b/flang/test/Lower/polymorphic.f90 @@ -249,4 +249,38 @@ ! CHECK: %[[CONVERT:.*]] = fir.convert %3 : (!fir.ref>) -> !fir.ptr> ! CHECK: fir.store %[[CONVERT]] to %[[PTR]] : !fir.ref>> + subroutine up_input(a) + class(*), intent(in) :: a + end subroutine + + subroutine pass_trivial_to_up() + call up_input('hello') + call up_input(1) + call up_input(2.5) + call up_input(.true.) + call up_input((-1.0,3)) + end subroutine + +! CHECK-LABEL: func.func @_QMpolymorphic_testPpass_trivial_to_up() { +! CHECK: %[[CHAR:.*]] = fir.address_of(@_QQcl.{{.*}}) : !fir.ref> +! CHECK: %[[EMBOX:.*]] = fir.embox %[[CHAR]] : (!fir.ref>) -> !fir.class> +! CHECK: %[[CONVERT:.*]] = fir.convert %[[EMBOX]] : (!fir.class>) -> !fir.class +! CHECK: fir.call @_QMpolymorphic_testPup_input(%[[CONVERT]]) {{.*}} : (!fir.class) -> () + +! CHECK: %[[BOX_INT:.*]] = fir.embox %{{.*}} : (!fir.ref) -> !fir.class +! CHECK: %[[UP:.*]] = fir.convert %[[BOX_INT]] : (!fir.class) -> !fir.class +! CHECK: fir.call @_QMpolymorphic_testPup_input(%[[UP]]) {{.*}} : (!fir.class) -> () + +! CHECK: %[[BOX_REAL:.*]] = fir.embox %{{.*}} : (!fir.ref) -> !fir.class +! CHECK: %[[UP:.*]] = fir.convert %[[BOX_REAL]] : (!fir.class) -> !fir.class +! CHECK: fir.call @_QMpolymorphic_testPup_input(%[[UP]]) {{.*}} : (!fir.class) -> () + +! CHECK: %[[BOX_LOG:.*]] = fir.embox %{{.*}} : (!fir.ref>) -> !fir.class> +! CHECK: %[[UP:.*]] = fir.convert %[[BOX_LOG]] : (!fir.class>) -> !fir.class +! CHECK: fir.call @_QMpolymorphic_testPup_input(%[[UP]]) {{.*}} : (!fir.class) -> () + +! CHECK: %[[BOX_COMPLEX:.*]] = fir.embox %{{.*}} : (!fir.ref>) -> !fir.class> +! CHECK: %[[UP:.*]] = fir.convert %[[BOX_COMPLEX]] : (!fir.class>) -> !fir.class +! CHECK: fir.call @_QMpolymorphic_testPup_input(%[[UP]]) {{.*}} : (!fir.class) -> () + end module