[flang-commits] [flang] 7ccc7e5 - [flang] Fix to IsDescriptor

Tim Keith via flang-commits flang-commits at lists.llvm.org
Thu May 7 07:52:16 PDT 2020


Author: Tim Keith
Date: 2020-05-07T07:51:45-07:00
New Revision: 7ccc7e56724974a27c8ada44f3cf0be0b5b1f4c2

URL: https://github.com/llvm/llvm-project/commit/7ccc7e56724974a27c8ada44f3cf0be0b5b1f4c2
DIFF: https://github.com/llvm/llvm-project/commit/7ccc7e56724974a27c8ada44f3cf0be0b5b1f4c2.diff

LOG: [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

Added: 
    

Modified: 
    flang/include/flang/Semantics/type.h
    flang/lib/Evaluate/type.cpp
    flang/lib/Semantics/type.cpp
    flang/test/Semantics/offsets01.f90

Removed: 
    


################################################################################
diff  --git a/flang/include/flang/Semantics/type.h b/flang/include/flang/Semantics/type.h
index c431a3b9731b..c99cdb715a7f 100644
--- a/flang/include/flang/Semantics/type.h
+++ b/flang/include/flang/Semantics/type.h
@@ -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.

diff  --git a/flang/lib/Evaluate/type.cpp b/flang/lib/Evaluate/type.cpp
index 3ff085777dfa..3360d30d9f93 100644
--- a/flang/lib/Evaluate/type.cpp
+++ b/flang/lib/Evaluate/type.cpp
@@ -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) {

diff  --git a/flang/lib/Semantics/type.cpp b/flang/lib/Semantics/type.cpp
index 80f994045749..c02ab6b6afd3 100644
--- a/flang/lib/Semantics/type.cpp
+++ b/flang/lib/Semantics/type.cpp
@@ -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) {

diff  --git a/flang/test/Semantics/offsets01.f90 b/flang/test/Semantics/offsets01.f90
index aa4f79612834..f5491f7b9438 100644
--- a/flang/test/Semantics/offsets01.f90
+++ b/flang/test/Semantics/offsets01.f90
@@ -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


        


More information about the flang-commits mailing list