[flang] Prevent any non constant result extent to be inlined on caller side
authorJean Perier <jperier@nvidia.com>
Wed, 19 Jan 2022 18:12:12 +0000 (19:12 +0100)
committerJean Perier <jperier@nvidia.com>
Wed, 19 Jan 2022 18:15:49 +0000 (19:15 +0100)
commit81c66933292b8f7ea105122f39e0a06038744a88
treed186f56d422c97a8e6f9eea5cf292932f406b89f
parent0aae2bf37318eff2ac4abeb570383d9d603be552
[flang] Prevent any non constant result extent to be inlined on caller side

UBOUND, SIZE, and SHAPE folding was still creating expressions that are
invalid on the caller side without the call expression context.
A previous patch intended to deal with this situation (https://reviews.llvm.org/D116933)
but it assumed the return expression would be a descriptor inquiry to
the result symbol, which is not the case if the extent expression is
"scope invariant" inside the called subroutine (e.g., referring to
intent(in) dummy arguments). Simply prevent folding from inlining non
constant extent expression on the caller side.

Folding could be later improved by having ad-hoc folding for UBOUND, SIZE, and
SHAPE on function references where it could try replacing the dummy symbols
by the actual expression, but this is left as a possible later improvement.

Differential Revision: https://reviews.llvm.org/D117686
flang/lib/Evaluate/shape.cpp
flang/test/Evaluate/rewrite01.f90