[flang-commits] [flang] [flang] Don't accept NULL() actual for assumed-rank dummy (PR #71574)

via flang-commits flang-commits at lists.llvm.org
Tue Nov 7 10:53:35 PST 2023


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-flang-semantics

Author: Peter Klausler (klausler)

<details>
<summary>Changes</summary>

A NULL() pointer without MOLD= cannot be allowed to be associated with an assumed-rank dummy argument, as its rank is not well-defined and neither the RANK() intrinsic function or the SELECT RANK construct will work in the callee.

---
Full diff: https://github.com/llvm/llvm-project/pull/71574.diff


3 Files Affected:

- (modified) flang/docs/Extensions.md (+3) 
- (modified) flang/lib/Semantics/check-call.cpp (+4) 
- (modified) flang/test/Semantics/call39.f90 (+4) 


``````````diff
diff --git a/flang/docs/Extensions.md b/flang/docs/Extensions.md
index 1aa0e03253455eb..ee85263f88c98a6 100644
--- a/flang/docs/Extensions.md
+++ b/flang/docs/Extensions.md
@@ -93,6 +93,9 @@ end
   non-global name in the same scope.  This is not conforming,
   but it is useful and unambiguous.
 * The argument to `RANDOM_NUMBER` may not be an assumed-size array.
+* `NULL()` without `MOLD=` is not allowed to be associated as an
+  actual argument corresponding to an assumed-rank dummy argument;
+  its rank in the called procedure would not be well-defined.
 
 ## Extensions, deletions, and legacy features supported by default
 
diff --git a/flang/lib/Semantics/check-call.cpp b/flang/lib/Semantics/check-call.cpp
index bf80dbecab009d9..d1a5d9a18fdbd35 100644
--- a/flang/lib/Semantics/check-call.cpp
+++ b/flang/lib/Semantics/check-call.cpp
@@ -1077,6 +1077,10 @@ static void CheckExplicitInterfaceArg(evaluate::ActualArgument &arg,
                 } else if (object.type.type().IsTypelessIntrinsicArgument() &&
                     evaluate::IsNullObjectPointer(*expr)) {
                   // ok, ASSOCIATED(NULL(without MOLD=))
+                } else if (object.type.attrs().test(characteristics::
+                                   TypeAndShape::Attr::AssumedRank)) {
+                  messages.Say(
+                      "NULL() without MOLD= must not be associated with an assumed-rank dummy argument"_err_en_US);
                 } else if ((object.attrs.test(characteristics::DummyDataObject::
                                     Attr::Pointer) ||
                                object.attrs.test(characteristics::
diff --git a/flang/test/Semantics/call39.f90 b/flang/test/Semantics/call39.f90
index 860ab0096401403..41eeba10034786b 100644
--- a/flang/test/Semantics/call39.f90
+++ b/flang/test/Semantics/call39.f90
@@ -23,5 +23,9 @@ subroutine test
     call s1(null(a1)) ! ok
     call sa(null(a0)) ! ok
     call sa(null(a1)) ! ok
+    !ERROR: NULL() without MOLD= must not be associated with an assumed-rank dummy argument
+    call sa(null())
+    !ERROR: NULL() without MOLD= must not be associated with an assumed-rank dummy argument
+    call sa(null())
   end
 end

``````````

</details>


https://github.com/llvm/llvm-project/pull/71574


More information about the flang-commits mailing list