[flang-commits] [flang] 394d6fc - [flang] Check ArrayRef base for contiguity in IsSimplyContiguousHelper

Jean Perier via flang-commits flang-commits at lists.llvm.org
Wed Nov 17 09:19:58 PST 2021


Author: Jean Perier
Date: 2021-11-17T18:18:58+01:00
New Revision: 394d6fcf3eb98f99045df506e587ac7cbf15e7a4

URL: https://github.com/llvm/llvm-project/commit/394d6fcf3eb98f99045df506e587ac7cbf15e7a4
DIFF: https://github.com/llvm/llvm-project/commit/394d6fcf3eb98f99045df506e587ac7cbf15e7a4.diff

LOG: [flang] Check ArrayRef base for contiguity in IsSimplyContiguousHelper

Previous code was returning true for `x(:)` where x is a pointer without
the contiguous attribute.
In case the array ref is a whole array section, check the base for contiguity
to solve the issue.

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

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/flang/lib/Evaluate/check-expression.cpp b/flang/lib/Evaluate/check-expression.cpp
index 53c93354c2393..702ddca8567fe 100644
--- a/flang/lib/Evaluate/check-expression.cpp
+++ b/flang/lib/Evaluate/check-expression.cpp
@@ -678,8 +678,15 @@ class IsSimplyContiguousHelper
     if (!(*this)(symbol).has_value()) {
       return false;
     } else if (auto rank{CheckSubscripts(x.subscript())}) {
-      // a(:)%b(1,1) is not contiguous; a(1)%b(:,:) is
-      return *rank > 0 || x.Rank() == 0;
+      if (x.Rank() == 0) {
+        return true;
+      } else if (*rank > 0) {
+        // a(1)%b(:,:) is contiguous if an only if a(1)%b is contiguous.
+        return (*this)(x.base());
+      } else {
+        // a(:)%b(1,1) is not contiguous.
+        return false;
+      }
     } else {
       return false;
     }

diff  --git a/flang/test/Semantics/assign03.f90 b/flang/test/Semantics/assign03.f90
index c8fed50a18f05..ce5897d41dc6c 100644
--- a/flang/test/Semantics/assign03.f90
+++ b/flang/test/Semantics/assign03.f90
@@ -277,6 +277,8 @@ subroutine s12
     logical, parameter :: l4 = is_contiguous(x%a(:,v))
     !ERROR: Must be a constant value
     logical, parameter :: l5 = is_contiguous(y(v,1)%a(1,1))
+    !ERROR: Must be a constant value
+    logical, parameter :: l6 = is_contiguous(p(:))
   end
   subroutine test3(b)
     integer, intent(inout) :: b(..)


        


More information about the flang-commits mailing list