diff --git a/flang/lib/Semantics/check-call.cpp b/flang/lib/Semantics/check-call.cpp --- a/flang/lib/Semantics/check-call.cpp +++ b/flang/lib/Semantics/check-call.cpp @@ -635,7 +635,9 @@ dummyName); } } else if (IsNullPointer(*expr)) { - if (!dummyIsPointer) { + if (!dummyIsPointer && + !dummy.attrs.test( + characteristics::DummyProcedure::Attr::Optional)) { messages.Say( "Actual argument associated with procedure %s is a null pointer"_err_en_US, dummyName); diff --git a/flang/test/Semantics/call02.f90 b/flang/test/Semantics/call02.f90 --- a/flang/test/Semantics/call02.f90 +++ b/flang/test/Semantics/call02.f90 @@ -15,6 +15,12 @@ !ERROR: A dummy procedure may not be ELEMENTAL procedure(elem) :: dummy end subroutine + subroutine optionalsubr(dummy) + procedure(sin), optional :: dummy + end subroutine + subroutine ptrsubr(dummy) + procedure(sin), pointer, intent(in) :: dummy + end subroutine end interface intrinsic :: cos call subr(cos) ! not an error @@ -22,6 +28,8 @@ call subr(elem) ! C1533 !ERROR: Actual argument associated with procedure dummy argument 'dummy=' is a null pointer call subr(null()) + call optionalsubr(null()) ! ok + call ptrsubr(null()) ! ok !ERROR: Actual argument associated with procedure dummy argument 'dummy=' is typeless call subr(B"1010") end subroutine