[flang][runtime] Fixes for element size calculation.
authorSlava Zakharin <szakharin@nvidia.com>
Thu, 22 Sep 2022 16:31:20 +0000 (09:31 -0700)
committerSlava Zakharin <szakharin@nvidia.com>
Thu, 22 Sep 2022 17:10:42 +0000 (10:10 -0700)
commitd37250c9db48d12b6ba66e10a2ccaf8e3e66b547
tree2093e82cf83d1b274a048dc82e4fc578b199f5e4
parent0ca5993741877ab7fd27a251cbc1895bd092d5ee
[flang][runtime] Fixes for element size calculation.

BytesFor() used to return KIND for the size, which is not always
correct, so I changed it to return the size of the actual CppType
corresponding to the given category and kind.

MinElemLen() used to calculate size incorrectly (e.g. CFI_type_extended_double
was sized 10, whereas it may occupy more bytes on a target), so I changed it
to call BytesFor().

Additional changes were needed to resolve new failures for transformational
intrinsics. These intrinsics used to work for not fully supported
data types (e.g. REAL(3)), but now stopped working because CppType
cannot be computed for those categories/kinds. The solution is to use
known element size from the source argument(s) for establishing
the destination descriptor - the element size is all that is needed
for transformational intrinsics to keep working.

Note that this does not help cases, where runtime still has to
compute the element size, e.g. when it creates descriptors for
components of derived types. If the component has unsupported
data type, BytesFor() will still fail. So these cases require
adding support for the missing types.

New regression unit test in Runtime/Transformational.cpp
demonstrates the case that will start working properly with
this commit.
flang/include/flang/Runtime/descriptor.h
flang/runtime/ISO_Fortran_binding.cpp
flang/runtime/ISO_Fortran_util.h [new file with mode: 0644]
flang/runtime/descriptor.cpp
flang/runtime/extrema.cpp
flang/runtime/reduction-templates.h
flang/runtime/reduction.cpp
flang/runtime/type-code.cpp
flang/unittests/Runtime/Transformational.cpp