From: Valentin Clement Date: Tue, 24 Jan 2023 13:45:17 +0000 (+0100) Subject: [flang] Handle passing NULL() to polymorphic pointer argument X-Git-Tag: upstream/17.0.6~19823 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f55bfde5f1b2bd65675fd2378bafa7caf771f3a9;p=platform%2Fupstream%2Fllvm.git [flang] Handle passing NULL() to polymorphic pointer argument Only updates the assert to check where the box is a BaseBoxType instead of a BoxType since ClassType are also valid in that case. Reviewed By: jeanPerier Differential Revision: https://reviews.llvm.org/D142442 --- diff --git a/flang/lib/Lower/ConvertExpr.cpp b/flang/lib/Lower/ConvertExpr.cpp index fdb6291..6c49302 100644 --- a/flang/lib/Lower/ConvertExpr.cpp +++ b/flang/lib/Lower/ConvertExpr.cpp @@ -2558,7 +2558,7 @@ public: // 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 52e4498..fe6ae87 100644 --- a/flang/test/Lower/polymorphic.f90 +++ b/flang/test/Lower/polymorphic.f90 @@ -824,6 +824,21 @@ module polymorphic_test ! 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