[all-commits] [llvm/llvm-project] fb3faa: [flang] Do not lose call in shape inquiry on funct...

jeanPerier via All-commits all-commits at lists.llvm.org
Mon Jan 10 10:15:59 PST 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: fb3faa8b326da5609723930b60c9949961f17c5b
      https://github.com/llvm/llvm-project/commit/fb3faa8b326da5609723930b60c9949961f17c5b
  Author: Jean Perier <jperier at nvidia.com>
  Date:   2022-01-10 (Mon, 10 Jan 2022)

  Changed paths:
    M flang/include/flang/Evaluate/shape.h
    M flang/lib/Evaluate/fold-integer.cpp
    M flang/lib/Evaluate/shape.cpp
    A flang/test/Evaluate/rewrite01.f90

  Log Message:
  -----------
  [flang] Do not lose call in shape inquiry on function reference

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.

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




More information about the All-commits mailing list