[flang] Allow NULL() actual argument for optional dummy procedure
authorPeter Klausler <pklausler@nvidia.com>
Tue, 3 May 2022 17:10:11 +0000 (10:10 -0700)
committerPeter Klausler <pklausler@nvidia.com>
Tue, 10 May 2022 00:41:39 +0000 (17:41 -0700)
A disassociated procedure pointer is allowed to be passed as an absent
actual argument that corresponds to an optional dummy procedure,
but not NULL(); accept that case as well.

Differential Revision: https://reviews.llvm.org/D125127

flang/lib/Semantics/check-call.cpp
flang/test/Semantics/call02.f90

index 8f49953..fee7162 100644 (file)
@@ -635,7 +635,9 @@ static void CheckProcedureArg(evaluate::ActualArgument &arg,
               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);
index dfd1ba5..a4ceaf6 100644 (file)
@@ -15,6 +15,12 @@ subroutine s01(elem, subr)
       !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 @@ subroutine s01(elem, subr)
   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