[flang-commits] [flang] [flang] Catch NULL(MOLD=assumed-rank) (PR #95270)

Peter Klausler via flang-commits flang-commits at lists.llvm.org
Wed Jun 12 10:11:02 PDT 2024


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

An assumed-rank dummy argument is not an acceptable MOLD argument to NULL(), whose result must have a known rank at compilation time.

>From dcd6b84ddc35fcd375a30eb86cde8d5e9d404334 Mon Sep 17 00:00:00 2001
From: Peter Klausler <pklausler at nvidia.com>
Date: Wed, 12 Jun 2024 10:06:55 -0700
Subject: [PATCH] [flang] Catch NULL(MOLD=assumed-rank)

An assumed-rank dummy argument is not an acceptable MOLD argument
to NULL(), whose result must have a known rank at compilation time.
---
 flang/lib/Evaluate/intrinsics.cpp | 4 ++++
 flang/test/Semantics/null01.f90   | 8 +++++++-
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/flang/lib/Evaluate/intrinsics.cpp b/flang/lib/Evaluate/intrinsics.cpp
index 58c1b6989f495..ace316174a892 100644
--- a/flang/lib/Evaluate/intrinsics.cpp
+++ b/flang/lib/Evaluate/intrinsics.cpp
@@ -2691,6 +2691,10 @@ SpecificCall IntrinsicProcTable::Implementation::HandleNull(
       mold = nullptr;
     }
     if (mold) {
+      if (IsAssumedRank(*arguments[0])) {
+        context.messages().Say(arguments[0]->sourceLocation(),
+            "MOLD= argument to NULL() must not be assumed-rank"_err_en_US);
+      }
       bool isProcPtrTarget{
           IsProcedurePointerTarget(*mold) && !IsNullObjectPointer(*mold)};
       if (isProcPtrTarget || IsAllocatableOrPointerObject(*mold)) {
diff --git a/flang/test/Semantics/null01.f90 b/flang/test/Semantics/null01.f90
index 3bf620048e2f2..04d94865356b0 100644
--- a/flang/test/Semantics/null01.f90
+++ b/flang/test/Semantics/null01.f90
@@ -151,10 +151,16 @@ subroutine s1(x)
   subroutine s2(x)
     type(pdt(*)), pointer, intent(in) :: x
   end
-  subroutine test
+  subroutine s3(ar)
+    real, pointer :: ar(..)
+  end
+  subroutine test(ar)
+    real, pointer :: ar(..)
     !ERROR: Actual argument associated with dummy argument 'x=' is a NULL() pointer without a MOLD= to provide a character length
     call s1(null())
     !ERROR: Actual argument associated with dummy argument 'x=' is a NULL() pointer without a MOLD= to provide a value for the assumed type parameter 'n'
     call s2(null())
+    !ERROR: MOLD= argument to NULL() must not be assumed-rank
+    call s3(null(ar))
   end
 end



More information about the flang-commits mailing list