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

Peter Klausler via flang-commits flang-commits at lists.llvm.org
Tue Nov 7 10:52:57 PST 2023


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

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.

>From fd5c84cb9b212efe459cc5e235a39208834d1866 Mon Sep 17 00:00:00 2001
From: Peter Klausler <pklausler at nvidia.com>
Date: Mon, 6 Nov 2023 16:57:28 -0800
Subject: [PATCH] [flang] Don't accept NULL() actual for assumed-rank dummy

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.
---
 flang/docs/Extensions.md           | 3 +++
 flang/lib/Semantics/check-call.cpp | 4 ++++
 flang/test/Semantics/call39.f90    | 4 ++++
 3 files changed, 11 insertions(+)

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



More information about the flang-commits mailing list