[flang-commits] [PATCH] D116933: [flang] Do not lose call in shape inquiry on function reference

Jean Perier via Phabricator via flang-commits flang-commits at lists.llvm.org
Mon Jan 10 05:38:43 PST 2022


jeanPerier created this revision.
jeanPerier added a reviewer: klausler.
jeanPerier added a project: Flang.
Herald added a subscriber: jdoerfert.
Herald added a reviewer: sscalpone.
jeanPerier requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Currently, something like `print *, size(foo(n,m))` was rewritten
to `print *, size(foo_result_symbol)` when foo result is a non constant
shape array. This cannot be processed by lowering or reprocessed by a
Fortran compiler since the syntax is wrong (`foo_result_symbol` is
unknown on the caller side) and the arguments are lost when they might
be required to compute the result shape.

It is not possible (and probably not desired) to make GetShape fail in
general in such case since returning nullopt seems only expected for
scalars or assumed rank (see GetRank usage in lib/Semantics/check-call.cpp),
and returning a vector with nullopt extent may trigger some checks to
believe they are facing an assumed size (like here in intrinsic argument
checks: https://github.com/llvm/llvm-project/blob/196204c72c68a577c72af95d70f18e3550939a5e/flang/lib/Evaluate/intrinsics.cpp#L1530).

Hence, I went for a solution that limits the rewrite change to folding
(where the original expression is returned if the shape depends on a non
constant shape from a call).

I added a non default option to GetShapeHelper that prevents the rewrite
of shape inquiry on calls to descriptor inquiries. At first I wanted to
avoid touching GetShapeHelper, but it would require to re-implement all
its logic to determine if the shape comes from a function call or not
(the expression could be `size(1+foo(n,m))`). So added an alternate
entry point to GetShapeHelper seemed the cleanest solution to me.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D116933

Files:
  flang/include/flang/Evaluate/shape.h
  flang/lib/Evaluate/fold-integer.cpp
  flang/lib/Evaluate/shape.cpp
  flang/test/Evaluate/rewrite01.f90

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D116933.398594.patch
Type: text/x-patch
Size: 5785 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20220110/9da73461/attachment.bin>


More information about the flang-commits mailing list