[flang-commits] [PATCH] D125127: [flang] Allow NULL() actual argument for optional dummy procedure

Peter Klausler via Phabricator via flang-commits flang-commits at lists.llvm.org
Fri May 6 13:34:53 PDT 2022


klausler created this revision.
klausler added a reviewer: PeteSteinfeld.
klausler added a project: Flang.
Herald added a subscriber: jdoerfert.
Herald added a project: All.
klausler requested review of this revision.

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.


https://reviews.llvm.org/D125127

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


Index: flang/test/Semantics/call02.f90
===================================================================
--- flang/test/Semantics/call02.f90
+++ 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
Index: flang/lib/Semantics/check-call.cpp
===================================================================
--- flang/lib/Semantics/check-call.cpp
+++ flang/lib/Semantics/check-call.cpp
@@ -630,7 +630,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);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D125127.427728.patch
Type: text/x-patch
Size: 1521 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20220506/d0eef322/attachment-0001.bin>


More information about the flang-commits mailing list