[flang-commits] [PATCH] D79349: [flang] Fix to IsDescriptor

Peter Klausler via Phabricator via flang-commits flang-commits at lists.llvm.org
Mon May 4 12:22:16 PDT 2020


klausler created this revision.
klausler added reviewers: tskeith, sscalpone.
klausler added a project: Flang.
Herald added a reviewer: jdoerfert.
Herald added a reviewer: DavidTruby.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
klausler retitled this revision from "Fix to IsDescriptor" to "[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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D79349

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


Index: flang/test/Semantics/offsets01.f90
===================================================================
--- flang/test/Semantics/offsets01.f90
+++ flang/test/Semantics/offsets01.f90
@@ -49,4 +49,6 @@
   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
Index: flang/lib/Semantics/type.cpp
===================================================================
--- flang/lib/Semantics/type.cpp
+++ flang/lib/Semantics/type.cpp
@@ -507,6 +507,13 @@
 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) {
Index: flang/lib/Evaluate/type.cpp
===================================================================
--- flang/lib/Evaluate/type.cpp
+++ flang/lib/Evaluate/type.cpp
@@ -31,13 +31,8 @@
       }
     }
   }
-  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) {
Index: flang/include/flang/Semantics/type.h
===================================================================
--- flang/include/flang/Semantics/type.h
+++ flang/include/flang/Semantics/type.h
@@ -223,6 +223,7 @@
   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.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D79349.261889.patch
Type: text/x-patch
Size: 2105 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20200504/09e580e3/attachment-0001.bin>


More information about the flang-commits mailing list