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] Catch NULL(MOLD=assumed-rank) #95270

Merged
merged 1 commit into from
Jun 13, 2024
Merged

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

merged 1 commit into from
Jun 13, 2024

Conversation

klausler
Copy link
Contributor

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

An assumed-rank dummy argument is not an acceptable MOLD argument
to NULL(), whose result must have a known rank at compilation time.
@klausler klausler requested a review from jeanPerier June 12, 2024 17:10
@llvmbot llvmbot added flang Flang issues not falling into any other category flang:semantics labels Jun 12, 2024
@llvmbot
Copy link
Member

llvmbot commented Jun 12, 2024

@llvm/pr-subscribers-flang-semantics

Author: Peter Klausler (klausler)

Changes

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


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

2 Files Affected:

  • (modified) flang/lib/Evaluate/intrinsics.cpp (+4)
  • (modified) flang/test/Semantics/null01.f90 (+7-1)
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

Copy link
Contributor

@jeanPerier jeanPerier left a comment

Choose a reason for hiding this comment

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

Thanks for adding safety here!

@klausler klausler merged commit 2414a90 into llvm:main Jun 13, 2024
10 checks passed
@klausler klausler deleted the ar-null branch June 13, 2024 17:57
EthanLuisMcDonough pushed a commit to EthanLuisMcDonough/llvm-project that referenced this pull request Aug 13, 2024
An assumed-rank dummy argument is not an acceptable MOLD argument to
NULL(), whose result must have a known rank at compilation time.
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