Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[flang] Accept NULL() actual for optional allocatable dummy argument #66251

Merged
merged 1 commit into from
Sep 18, 2023

Conversation

klausler
Copy link
Contributor

A NULL() pointer is an acceptable actual argument for association with an (absent) optional allocatable dummy argument. Semantics was unconditionally emitting an error that the actual argument is not allocatable.

A NULL() pointer is an acceptable actual argument for association
with an (absent) optional allocatable dummy argument.  Semantics
was unconditionally emitting an error that the actual argument
is not allocatable.

Pull request: llvm#66251
@klausler klausler requested a review from vdonaldson September 13, 2023 17:11
@klausler klausler requested a review from a team as a code owner September 13, 2023 17:11
@llvmbot llvmbot added flang Flang issues not falling into any other category flang:semantics labels Sep 13, 2023
@llvmbot
Copy link
Member

llvmbot commented Sep 13, 2023

@llvm/pr-subscribers-flang-semantics

Changes A NULL() pointer is an acceptable actual argument for association with an (absent) optional allocatable dummy argument. Semantics was unconditionally emitting an error that the actual argument is not allocatable. -- Full diff: https://github.com//pull/66251.diff

2 Files Affected:

  • (modified) flang/lib/Semantics/check-call.cpp (+4-4)
  • (modified) flang/test/Semantics/null01.f90 (+4)
diff --git a/flang/lib/Semantics/check-call.cpp b/flang/lib/Semantics/check-call.cpp
index c48c382218dc9bb..12dc0b390edf5a5 100644
--- a/flang/lib/Semantics/check-call.cpp
+++ b/flang/lib/Semantics/check-call.cpp
@@ -658,8 +658,11 @@ static void CheckExplicitDataArg(const characteristics::DummyDataObject &dummy,
 
   // 15.5.2.6 -- dummy is ALLOCATABLE
   bool actualIsAllocatable{evaluate::IsAllocatableDesignator(actual)};
+  bool dummyIsOptional{
+      dummy.attrs.test(characteristics::DummyDataObject::Attr::Optional)};
+  bool actualIsNull{evaluate::IsNullPointer(actual)};
   if (dummyIsAllocatable) {
-    if (!actualIsAllocatable) {
+    if (!actualIsAllocatable && !(actualIsNull && dummyIsOptional)) {
       messages.Say(
           "ALLOCATABLE %s must be associated with an ALLOCATABLE actual argument"_err_en_US,
           dummyName);
@@ -788,9 +791,6 @@ static void CheckExplicitDataArg(const characteristics::DummyDataObject &dummy,
   }
 
   // NULL(MOLD=) checking for non-intrinsic procedures
-  bool dummyIsOptional{
-      dummy.attrs.test(characteristics::DummyDataObject::Attr::Optional)};
-  bool actualIsNull{evaluate::IsNullPointer(actual)};
   if (!intrinsic && !dummyIsPointer && !dummyIsOptional && actualIsNull) {
     messages.Say(
         "Actual argument associated with %s may not be null pointer %s"_err_en_US,
diff --git a/flang/test/Semantics/null01.f90 b/flang/test/Semantics/null01.f90
index 02a68147a7527ad..71567fb0a673465 100644
--- a/flang/test/Semantics/null01.f90
+++ b/flang/test/Semantics/null01.f90
@@ -12,6 +12,9 @@ subroutine canbenull(x, y)
       integer, intent(in), optional :: x
       real, intent(in), pointer :: y
     end
+    subroutine optionalAllocatable(x)
+      integer, intent(in), allocatable, optional :: x
+    end
     function f0()
       real :: f0
     end function
@@ -95,6 +98,7 @@ function f3()
   dt4x = dt4(null(dt2x%pps0))
   call canbenull(null(), null()) ! fine
   call canbenull(null(mold=ip0), null(mold=rp0)) ! fine
+  call optionalAllocatable(null(mold=ip0)) ! fine
   !ERROR: Null pointer argument requires an explicit interface
   call implicit(null())
   !ERROR: Null pointer argument requires an explicit interface

@klausler klausler merged commit b76e08d into llvm:main Sep 18, 2023
@klausler klausler deleted the e6a branch September 18, 2023 18:54
ZijunZhaoCCK pushed a commit to ZijunZhaoCCK/llvm-project that referenced this pull request Sep 19, 2023
…lvm#66251)

A NULL() pointer is an acceptable actual argument for association with
an (absent) optional allocatable dummy argument. Semantics was
unconditionally emitting an error that the actual argument is not
allocatable.
zahiraam pushed a commit to tahonermann/llvm-project that referenced this pull request Oct 24, 2023
…lvm#66251)

A NULL() pointer is an acceptable actual argument for association with
an (absent) optional allocatable dummy argument. Semantics was
unconditionally emitting an error that the actual argument is not
allocatable.
zahiraam pushed a commit to tahonermann/llvm-project that referenced this pull request Oct 24, 2023
…lvm#66251)

A NULL() pointer is an acceptable actual argument for association with
an (absent) optional allocatable dummy argument. Semantics was
unconditionally emitting an error that the actual argument is not
allocatable.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang Flang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants