[flang][lowering] Handle zero extent case in LBOUND
authorJean Perier <jperier@nvidia.com>
Fri, 25 Mar 2022 17:01:50 +0000 (18:01 +0100)
committerJean Perier <jperier@nvidia.com>
Fri, 25 Mar 2022 17:05:54 +0000 (18:05 +0100)
commit5bc9ee1b780656c6d7f27c4ca657c5a7815311c1
treef11706cb08b73e40445853cd26fe6ddbdaba6c67
parentec858f02015c32c683852fe72761a2e610dc5785
[flang][lowering] Handle zero extent case in LBOUND

Follow up of https://reviews.llvm.org/D121488. Ensure lower bounds
are `1` when the related dimension extent is zero. Note that lower
bounds from descriptors are now guaranteed to fulfill this property
after the runtime/codegen patches.

Also fixes explicit shape array extent lowering when instantiating
variables to deal with negative extent cases (issue found while testing
LBOUND edge case). This notably caused allocation crashes when dealing
with automatic arrays with reversed bounds or negative size
specification expression. The standard specifies that the extent of such
arrays is zero. This change has some ripple effect in the current lit
tests.

Add move two helpers as part of this change:
- Add a helper to tell if a fir::ExtendedValue describes an assumed size
  array (last dimension extent is unknown to the compiler, both at compile
  time and runtime).

- Move and share getIntIfConstant from Character.cpp so that it can be
  used elsewhere (NFC).

Differential Revision: https://reviews.llvm.org/D122467
flang/include/flang/Optimizer/Builder/BoxValue.h
flang/include/flang/Optimizer/Builder/FIRBuilder.h
flang/lib/Lower/ConvertVariable.cpp
flang/lib/Lower/IntrinsicCall.cpp
flang/lib/Optimizer/Builder/BoxValue.cpp
flang/lib/Optimizer/Builder/Character.cpp
flang/lib/Optimizer/Builder/FIRBuilder.cpp
flang/test/Lower/array-expression.f90
flang/test/Lower/call-parenthesized-arg.f90
flang/test/Lower/character-local-variables.f90
flang/test/Lower/forall/test9.f90