[flang] Fix LBOUND with assumed size array and non constant DIM
authorValentin Clement <clementval@gmail.com>
Fri, 24 Jun 2022 19:01:25 +0000 (21:01 +0200)
committerValentin Clement <clementval@gmail.com>
Fri, 24 Jun 2022 19:02:07 +0000 (21:02 +0200)
commit4489ef8e34fefcbbf4fe44d1307b0cc41a12cfa8
tree00c1b7528d91678edb3202e6e8b2d07e527455af
parentae8fac6f98dd6ee03442ccefa2b65087d73c4d36
[flang] Fix LBOUND with assumed size array and non constant DIM

LBOUND with a non constant DIM argument use the runtime to allow runtime
verification of DIM <= RANK. The interface uses a descriptor. This caused
undefined behavior because the runtime believed it was seeing an explicit
shape arrays with zero extent and returned `1` (the runtime descriptor
does not allow making a difference between an explicit shape and an
assumed size. Assumed size are not meant to be described by runtime
descriptors).

Fix the issue by setting the last extent of assumed size to `1` when
creating the descriptor to inquire about the LBOUND with the runtime.

This patch is part of the upstreaming effort from fir-dev branch.

Reviewed By: PeteSteinfeld

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

Co-authored-by: Jean Perier <jperier@nvidia.com>
flang/lib/Lower/IntrinsicCall.cpp
flang/test/Lower/Intrinsics/lbound.f90