[flang] Fix to IsDescriptor

IsDescriptor was returning false for a component whose shape depended
on a length parameter. Change it to return true for any array with
non-constant bounds.

Differential Revision: https://reviews.llvm.org/D79349
This commit is contained in:
Tim Keith 2020-05-07 07:50:39 -07:00
parent c54c6ee1a7
commit 7ccc7e5672
4 changed files with 11 additions and 6 deletions

View File

@ -223,6 +223,7 @@ struct ArraySpec : public std::vector<ShapeSpec> {
bool IsImpliedShape() const;
bool IsAssumedSize() const;
bool IsAssumedRank() const;
bool IsConstantShape() const; // explicit shape with constant bounds
private:
// Check non-empty and predicate is true for each element.

View File

@ -31,13 +31,8 @@ static bool IsDescriptor(const ObjectEntityDetails &details) {
}
}
}
if (details.IsAssumedShape() || details.IsDeferredShape() ||
details.IsAssumedRank()) {
return true;
}
// TODO: Explicit shape component array dependent on length parameter
// TODO: Automatic (adjustable) arrays - are they descriptors?
return false;
return !details.shape().empty() && !details.shape().IsConstantShape();
}
static bool IsDescriptor(const ProcEntityDetails &details) {

View File

@ -507,6 +507,13 @@ bool ArraySpec::IsAssumedSize() const {
bool ArraySpec::IsAssumedRank() const {
return Rank() == 1 && front().lbound().isAssumed();
}
bool ArraySpec::IsConstantShape() const {
return CheckAll([](const ShapeSpec &x) {
const auto &lb{x.lbound().GetExplicit()};
const auto &ub{x.ubound().GetExplicit()};
return lb && ub && IsConstantExpr(*lb) && IsConstantExpr(*ub);
});
}
llvm::raw_ostream &operator<<(
llvm::raw_ostream &os, const ArraySpec &arraySpec) {

View File

@ -49,4 +49,6 @@ subroutine s5(n)
end type
type(t1(n)) :: x1 !CHECK: x1 size=48 offset=
type(t2(n,n)) :: x2 !CHECK: x2 size=56 offset=
!CHECK: a size=48 offset=0:
!CHECK: b size=72 offset=0:
end