Skip to content

[flang] Accept ALLOCATED(ARRAY=assumedRank) #66233

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
Sep 13, 2023
Merged

[flang] Accept ALLOCATED(ARRAY=assumedRank) #66233

merged 1 commit into from
Sep 13, 2023

Conversation

klausler
Copy link
Contributor

The definitions of the ALLOCATED intrinsic in the intrinsics table did not allow for an assumed-rank array.

@klausler klausler requested a review from vzakhari September 13, 2023 16:37
@klausler klausler requested a review from a team as a code owner September 13, 2023 16:37
The definitions of the ALLOCATED intrinsic in the intrinsics table
did not allow for an assumed-rank array.

Pull request: llvm#66233
@llvmbot llvmbot added flang Flang issues not falling into any other category flang:semantics labels Sep 13, 2023
@llvmbot
Copy link
Member

llvmbot commented Sep 13, 2023

@llvm/pr-subscribers-flang-semantics

Changes The definitions of the ALLOCATED intrinsic in the intrinsics table did not allow for an assumed-rank array. -- Full diff: https://github.com//pull/66233.diff

2 Files Affected:

  • (modified) flang/lib/Evaluate/intrinsics.cpp (+2-2)
  • (modified) flang/test/Semantics/allocated.f90 (+10-1)
diff --git a/flang/lib/Evaluate/intrinsics.cpp b/flang/lib/Evaluate/intrinsics.cpp
index 030e5b2fd2c6d9d..7213482d9d798f3 100644
--- a/flang/lib/Evaluate/intrinsics.cpp
+++ b/flang/lib/Evaluate/intrinsics.cpp
@@ -315,10 +315,10 @@ static const IntrinsicInterface genericIntrinsicFunction[]{
     {"aint", {{"a", SameReal}, MatchingDefaultKIND}, KINDReal},
     {"all", {{"mask", SameLogical, Rank::array}, OptionalDIM}, SameLogical,
         Rank::dimReduced, IntrinsicClass::transformationalFunction},
-    {"allocated", {{"array", AnyData, Rank::array}}, DefaultLogical,
-        Rank::elemental, IntrinsicClass::inquiryFunction},
     {"allocated", {{"scalar", AnyData, Rank::scalar}}, DefaultLogical,
         Rank::elemental, IntrinsicClass::inquiryFunction},
+    {"allocated", {{"array", AnyData, Rank::anyOrAssumedRank}}, DefaultLogical,
+        Rank::elemental, IntrinsicClass::inquiryFunction},
     {"anint", {{"a", SameReal}, MatchingDefaultKIND}, KINDReal},
     {"any", {{"mask", SameLogical, Rank::array}, OptionalDIM}, SameLogical,
         Rank::dimReduced, IntrinsicClass::transformationalFunction},
diff --git a/flang/test/Semantics/allocated.f90 b/flang/test/Semantics/allocated.f90
index 82ce7ca7bdb9f80..a2eddaf82784aee 100644
--- a/flang/test/Semantics/allocated.f90
+++ b/flang/test/Semantics/allocated.f90
@@ -1,6 +1,7 @@
 ! RUN: %python %S/test_errors.py %s %flang_fc1
 ! Tests for the ALLOCATED() intrinsic
-subroutine alloc(coarray_alloc, coarray_not_alloc, t2_not_alloc)
+subroutine alloc(coarray_alloc, coarray_not_alloc, t2_not_alloc, &
+                 assumedRank)
 
   interface
     function return_allocatable()
@@ -30,6 +31,7 @@ function return_allocatable()
   real :: coarray_not_alloc(:)[*]
 
   type(t2) :: t2_not_alloc
+  real, allocatable :: assumedRank(..)
 
 
   ! OK
@@ -42,6 +44,13 @@ function return_allocatable()
   print *, allocated(coarray_alloc[2,3])
   print *, allocated(t2_not_alloc%coarray_alloc)
   print *, allocated(t2_not_alloc%coarray_alloc[2])
+  print *, allocated(assumedRank)
+  select rank (assumedRank)
+  rank (0)
+    print *, allocated(scalar=assumedRank)
+  rank default
+    print *, allocated(array=assumedRank)
+  end select
 
   !ERROR: Argument of ALLOCATED() must be an ALLOCATABLE object or component
   print *, allocated(not_alloc)

Copy link
Contributor

@vzakhari vzakhari left a comment

Choose a reason for hiding this comment

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

LGTM. Thank you!

@klausler klausler merged commit d34f5dd into llvm:main Sep 13, 2023
@klausler klausler deleted the p0 branch September 13, 2023 22:55
ZijunZhaoCCK pushed a commit to ZijunZhaoCCK/llvm-project that referenced this pull request Sep 19, 2023
The definitions of the ALLOCATED intrinsic in the intrinsics table did
not allow for an assumed-rank array.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang Flang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants