[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
This commit is contained in:
Jean Perier 2021-11-17 18:18:05 +01:00
parent e1ef14069e
commit 394d6fcf3e
2 changed files with 11 additions and 2 deletions

View File

@ -678,8 +678,15 @@ public:
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;
}

View File

@ -277,6 +277,8 @@ contains
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(..)