[flang] UBOUND() edge case: empty dimension
authorJean Perier <jperier@nvidia.com>
Thu, 24 Mar 2022 08:06:59 +0000 (09:06 +0100)
committerJean Perier <jperier@nvidia.com>
Thu, 24 Mar 2022 08:07:15 +0000 (09:07 +0100)
commitca46521a4d567ca808907d33a31b57d3097d34fa
treec4e882f843774a74c92f5fbd29e62895b7aaeff7
parent88d5289fc69d24e8490a064c87228d68c53e5d9c
[flang] UBOUND() edge case: empty dimension

Similarly to LBOUND in https://reviews.llvm.org/D121488, UBOUND must
return zero for an empty dimension, no matter the specification
expression.

Add a GetUBOUND method to be used in expression rewrite that prevents
folding UBOUND to a bound specification expression if the extent is
not a compile time constant.

Fold the case where the extents is known to be zero (and also deal with
this case in LBOUND since we can and should to comply with constant
expression requirements).

Differential Revision: https://reviews.llvm.org/D122242
flang/include/flang/Evaluate/shape.h
flang/lib/Evaluate/check-expression.cpp
flang/lib/Evaluate/fold-integer.cpp
flang/lib/Evaluate/shape.cpp
flang/lib/Semantics/runtime-type-info.cpp
flang/test/Evaluate/folding08.f90
flang/test/Evaluate/rewrite01.f90