diff --git a/flang/lib/Lower/ConvertExpr.cpp b/flang/lib/Lower/ConvertExpr.cpp index fdb6291b8e6c4..6c493024bd1cb 100644 --- a/flang/lib/Lower/ConvertExpr.cpp +++ b/flang/lib/Lower/ConvertExpr.cpp @@ -2558,7 +2558,7 @@ class ScalarExprLowering { // callee side, and it is illegal to use NULL without a MOLD if any // dummy length parameters are assumed. mlir::Type boxTy = fir::dyn_cast_ptrEleTy(argTy); - assert(boxTy && boxTy.isa() && + assert(boxTy && boxTy.isa() && "must be a fir.box type"); mlir::Value boxStorage = builder.createTemporary(loc, boxTy); mlir::Value nullBox = fir::factory::createUnallocatedBox( diff --git a/flang/test/Lower/polymorphic.f90 b/flang/test/Lower/polymorphic.f90 index 52e4498a8d765..fe6ae879c540c 100644 --- a/flang/test/Lower/polymorphic.f90 +++ b/flang/test/Lower/polymorphic.f90 @@ -824,6 +824,21 @@ subroutine sub_with_real_pointer_optional(p) ! CHECK: } ! CHECK: fir.call @_QMpolymorphic_testPsub_with_poly_array_optional(%[[BOX]]) {{.*}} : (!fir.class>) -> () + subroutine pass_poly_pointer_optional(p) + class(p1), pointer, optional :: p + end subroutine + + subroutine test_poly_pointer_null() + call pass_poly_pointer_optional(null()) + end subroutine + +! CHECK-LABEL: func.func @_QMpolymorphic_testPtest_poly_pointer_null() { +! CHECK: %[[ALLOCA:.*]] = fir.alloca !fir.class>> +! CHECK: %[[ZERO:.*]] = fir.zero_bits !fir.ptr> +! CHECK: %[[EMBOX:.*]] = fir.embox %[[ZERO]] : (!fir.ptr>) -> !fir.class>> +! CHECK: fir.store %[[EMBOX]] to %[[ALLOCA]] : !fir.ref>>> +! CHECK: fir.call @_QMpolymorphic_testPpass_poly_pointer_optional(%[[ALLOCA]]) fastmath : (!fir.ref>>>) -> () + end module program test