Skip to content

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

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

Merged
merged 1 commit into from
Nov 13, 2023

Conversation

klausler
Copy link
Contributor

@klausler klausler commented Nov 7, 2023

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.

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.
@klausler klausler requested a review from psteinfeld November 7, 2023 18:52
@llvmbot llvmbot added flang Flang issues not falling into any other category flang:semantics labels Nov 7, 2023
@llvmbot
Copy link
Member

llvmbot commented Nov 7, 2023

@llvm/pr-subscribers-flang-semantics

Author: Peter Klausler (klausler)

Changes

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 --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

Copy link
Contributor

@psteinfeld psteinfeld left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

@klausler klausler merged commit 36ad343 into llvm:main Nov 13, 2023
@klausler klausler deleted the v2 branch November 13, 2023 23:14
zahiraam pushed a commit to zahiraam/llvm-project that referenced this pull request Nov 20, 2023
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:semantics flang Flang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants