[flang-commits] [flang] 9d1938f - [flang] Return true in IsSymplyContiguous for allocatables

Jean Perier via flang-commits flang-commits at lists.llvm.org
Sun Nov 28 23:29:22 PST 2021


Author: Jean Perier
Date: 2021-11-29T08:28:26+01:00
New Revision: 9d1938fd1441935313ac0e44e39069bee8171a86

URL: https://github.com/llvm/llvm-project/commit/9d1938fd1441935313ac0e44e39069bee8171a86
DIFF: https://github.com/llvm/llvm-project/commit/9d1938fd1441935313ac0e44e39069bee8171a86.diff

LOG: [flang] Return true in IsSymplyContiguous for allocatables

The current code was relying on the fact that allocatables are deferred
shape and that isAssumedShape() should therefore return true for them.

This is not true, because the current parsing/semantic analysis always
builds a semantics::ArraySpec for `x(:)` that returns true to both
isDeferredShape()/isAssumedShape(), whether x is allocatable/pointer or
not.

It proved tricky to change this behavior, so this is a simple fix for
IsSymplyContiguous where it currently matters, but we most likely want
to investigate more and fix the isDeferredShape()/isAssumedShape() in
a second time.

Differential Revision: https://reviews.llvm.org/D114599

Added: 
    

Modified: 
    flang/lib/Evaluate/check-expression.cpp
    flang/test/Evaluate/folding09.f90

Removed: 
    


################################################################################
diff  --git a/flang/lib/Evaluate/check-expression.cpp b/flang/lib/Evaluate/check-expression.cpp
index 702ddca8567fe..88a08dc8a5c95 100644
--- a/flang/lib/Evaluate/check-expression.cpp
+++ b/flang/lib/Evaluate/check-expression.cpp
@@ -661,10 +661,15 @@ class IsSimplyContiguousHelper
       return true;
     } else if (semantics::IsPointer(ultimate)) {
       return false;
+    } else if (semantics::IsAllocatable(ultimate)) {
+      // TODO: this could be merged with the case below if
+      // details->IsAssumedShape() did not return true for allocatables. Current
+      // ArraySpec building in semantics does not allow making a 
diff erence
+      // between some_assumed_shape(:) and some_allocatable(:). Both
+      // isDeferredShape() and isAssumedShape() are true in each case.
+      return true;
     } else if (const auto *details{
                    ultimate.detailsIf<semantics::ObjectEntityDetails>()}) {
-      // N.B. ALLOCATABLEs are deferred shape, not assumed, and
-      // are obviously contiguous.
       return !details->IsAssumedShape() && !details->IsAssumedRank();
     } else if (auto assoc{Base::operator()(ultimate)}) {
       return assoc;

diff  --git a/flang/test/Evaluate/folding09.f90 b/flang/test/Evaluate/folding09.f90
index d78611f4b2a9b..58ddc44925e49 100644
--- a/flang/test/Evaluate/folding09.f90
+++ b/flang/test/Evaluate/folding09.f90
@@ -9,9 +9,10 @@ function f()
     real, pointer, contiguous :: f(:)
     f => hosted
   end function
-  subroutine test(arr1, arr2, arr3, mat)
+  subroutine test(arr1, arr2, arr3, mat, alloc)
     real, intent(in) :: arr1(:), arr2(10), mat(10, 10)
     real, intent(in), contiguous :: arr3(:)
+    real, allocatable :: alloc(:)
     real :: scalar
     logical, parameter :: test_isc01 = is_contiguous(0)
     logical, parameter :: test_isc02 = is_contiguous(scalar)
@@ -24,5 +25,6 @@ subroutine test(arr1, arr2, arr3, mat)
     logical, parameter :: test_isc09 = is_contiguous(arr2(1:10:1))
     logical, parameter :: test_isc10 = is_contiguous(arr3)
     logical, parameter :: test_isc11 = is_contiguous(f())
+    logical, parameter :: test_isc12 = is_contiguous(alloc)
   end subroutine
 end module


        


More information about the flang-commits mailing list