[flang] Fix LBOUND rewrite on descriptor components
authorJean Perier <jperier@nvidia.com>
Fri, 25 Mar 2022 08:00:23 +0000 (09:00 +0100)
committerJean Perier <jperier@nvidia.com>
Fri, 25 Mar 2022 08:00:56 +0000 (09:00 +0100)
commit7f1adbaba99512d5fbf45ec54585b41218535836
tree0abf20650edf5ab7602989d213a0520ee01539e8
parent3929f91397159adbb7e84e215a8c7bc6db31db97
[flang] Fix LBOUND rewrite on descriptor components

GetLowerBoundHelper rewrite in https://reviews.llvm.org/D121488 was
incorrect with POINTER/ALLOCATABLE components. The rewrite created a
descriptor inquiry to the component symbol only instead of the whole
named entity. The base information was lost, and not retrievable.
LBOUND(a(10)%p) became LBOUND(p).

Fix this regression, and also update DescriptorInquiry unparsing to
carry the kind information. DescriptorInquiries are KIND 8 expressions,
while LBOUND/SIZE/RANK, %LEN are default kind expressions.
This caused `print *,lbound(x,kind=8)` to unparse as `print*,lbound(x)` which is not
semantically the same (this unparsing issue was not an issue for
lowering, but I noticed it while writing my regression test).

Differential Revision: https://reviews.llvm.org/D122406
flang/lib/Evaluate/formatting.cpp
flang/lib/Evaluate/shape.cpp
flang/test/Evaluate/rewrite01.f90
flang/test/Semantics/modfile30.f90
flang/test/Semantics/modfile33.f90