[PATCH] D95449: [flang] Fix problems with constant arrays with lower bounds that are not 1

Pete Steinfeld via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 26 08:21:42 PST 2021


PeteSteinfeld created this revision.
PeteSteinfeld added reviewers: klausler, tskeith.
PeteSteinfeld requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

There were two problems with constant arrays whose lower bound is not 1.
First, when folding the arrays, we were creating the folded array to have lower
bounds of 1 but not re-adjusting their lower bounds to the declared values.
Second, we were not calculating the extents correctly.  Both of these problems
led to bogus error messages.

I fixed the first problem by adjusting the lower bounds in
NonPointerInitializationExpr() in Evaluate/check-expression.cpp.  I found an
existing class and method that did exactly what was needed that was originally
designed to expand a scalar value into an array called ScalarConstantExpander.
I renamed this class to reflect its generalization to ArrayConstantMaker.

I fixed the second problem by changing the formula that calculates upper bounds
in in the function ComputeUpperBound() in Evaluate/shape.cpp.

I added tests that trigger the bogus error messages mentioned above along with
a constant folding tests that uses array operands with shapes that conform but
have different bounds.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D95449

Files:
  flang/include/flang/Evaluate/tools.h
  flang/lib/Evaluate/check-expression.cpp
  flang/lib/Evaluate/fold.cpp
  flang/lib/Evaluate/shape.cpp
  flang/test/Evaluate/folding16.f90
  flang/test/Semantics/array-constr-values.f90

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D95449.319305.patch
Type: text/x-patch
Size: 7105 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210126/47b9abff/attachment.bin>


More information about the llvm-commits mailing list