[flang] Error detection/avoidance for TRANSFER with empty MOLD= type
authorPeter Klausler <pklausler@nvidia.com>
Fri, 8 Jul 2022 23:16:42 +0000 (16:16 -0700)
committerPeter Klausler <pklausler@nvidia.com>
Wed, 13 Jul 2022 23:50:57 +0000 (16:50 -0700)
commitbe68a6adfba29b275272cb36e606bc0cb08518b3
tree46007e6a700c11fd1e7b2e2731e84d46c6841a69
parente3923d000a6a0393bf6bd535b65433ed0de1ec28
[flang] Error detection/avoidance for TRANSFER with empty MOLD= type

When MOLD= is an array and there is no SIZE= in a call to TRANSFER(),
the size of an element of the MOLD= is used as the denominator in a
division to establish the extent of the vector result.  When the
total storage size of the SOURCE= is known to be zero, the result is
empty and no division is needed.

To avoid a division by zero at runtime, we need to check for a zero-sized
MOLD= element type when the storage size of SOURCE= is nonzero and there
is no SIZE=.  Further, in the compilation-time rewriting of calls to
SHAPE(TRANSFER(...)) and SIZE(TRANSFER(...)) for constant folding and
simplification purposes, we can't replace the call with an arithmetic
element count expression when the storage size of SOURCE= is not known
to be zero and the element size of MOLD= is not known to be nonzero at
compilation time.

These changes mostly affect tests using a MOLD= argument that is an
assumed-length character.

Differential Revision: https://reviews.llvm.org/D129680
flang/lib/Evaluate/shape.cpp
flang/runtime/misc-intrinsic.cpp