Skip to content

Commit 394d6fc

Browse files
committed
[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
1 parent e1ef140 commit 394d6fc

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

flang/lib/Evaluate/check-expression.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -678,8 +678,15 @@ class IsSimplyContiguousHelper
678678
if (!(*this)(symbol).has_value()) {
679679
return false;
680680
} else if (auto rank{CheckSubscripts(x.subscript())}) {
681-
// a(:)%b(1,1) is not contiguous; a(1)%b(:,:) is
682-
return *rank > 0 || x.Rank() == 0;
681+
if (x.Rank() == 0) {
682+
return true;
683+
} else if (*rank > 0) {
684+
// a(1)%b(:,:) is contiguous if an only if a(1)%b is contiguous.
685+
return (*this)(x.base());
686+
} else {
687+
// a(:)%b(1,1) is not contiguous.
688+
return false;
689+
}
683690
} else {
684691
return false;
685692
}

flang/test/Semantics/assign03.f90

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,8 @@ subroutine s12
277277
logical, parameter :: l4 = is_contiguous(x%a(:,v))
278278
!ERROR: Must be a constant value
279279
logical, parameter :: l5 = is_contiguous(y(v,1)%a(1,1))
280+
!ERROR: Must be a constant value
281+
logical, parameter :: l6 = is_contiguous(p(:))
280282
end
281283
subroutine test3(b)
282284
integer, intent(inout) :: b(..)

0 commit comments

Comments
 (0)