[all-commits] [llvm/llvm-project] 543cd8: [flang] Fix problems with constant arrays with low...

Pete Steinfeld via All-commits all-commits at lists.llvm.org
Fri Jan 29 08:15:40 PST 2021


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 543cd89d3fb5a108d4050635c00093695b2b6c6d
      https://github.com/llvm/llvm-project/commit/543cd89d3fb5a108d4050635c00093695b2b6c6d
  Author: Peter Steinfeld <psteinfeld at nvidia.com>
  Date:   2021-01-29 (Fri, 29 Jan 2021)

  Changed paths:
    M flang/include/flang/Evaluate/tools.h
    M flang/lib/Evaluate/check-expression.cpp
    M flang/lib/Evaluate/shape.cpp
    M flang/test/Evaluate/folding09.f90
    M flang/test/Evaluate/folding16.f90
    M flang/test/Evaluate/test_folding.sh
    M flang/test/Semantics/array-constr-values.f90

  Log Message:
  -----------
  [flang] Fix problems with constant arrays with lower bounds that are not 1

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, we were 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 wrote the
class ArrayConstantBoundChanger, which is similar to the existing class
ScalarConstantExpander.  In the process of implementing and testing it, I found
a bug that I fixed in ScalarConstantExpander which caused it to infinitely
recurse on parenthesized expressions.  I also removed the unrelated class
ScalarExpansionVisitor, which was not used.

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.

In the process of adding tests, I discovered that tests in
Evaluate/folding09.f90 and folding16.f90 were written incorrectly, and I
fixed them.  This also revealed a bug in contant folding of the
intrinsic "lbounds" which I plan to fix in a later change.

Differential Revision: https://reviews.llvm.org/D95449




More information about the All-commits mailing list