[flang] Handle correctly user defined assignment for allocatable component
authorValentin Clement <clementval@gmail.com>
Fri, 7 Apr 2023 18:47:35 +0000 (11:47 -0700)
committerValentin Clement <clementval@gmail.com>
Fri, 7 Apr 2023 18:47:54 +0000 (11:47 -0700)
commit3acdd596c0d7a51038f1be4a9bbc86ba288301ba
tree214caf65519981eebbfea0fac68ef7ee44c61312
parent13d44a8f5647819efd3ef57af384a3666f99d066
[flang] Handle correctly user defined assignment for allocatable component

In the Fortran standard 2018 section 10.2.1.3 (13), it is mentioned
that all noncoarray allocatable component must follow this sequence of
operations:

1) If the component of the variable is allocated, it is deallocated.
2) If the component of the value of expr is allocated, the corresponding
   component of the variable is allocated with the same dynamic type and
   type parameters as the component of the value of expr. If it is an
   array, it is allocated with the same bounds. The value of the
   component of the value of expr is then assigned to the corresponding
   component of the variable using defined assignment if the declared type
   of the component has a type-bound defined assignment consistent with the
   component, and intrinsic assignment for the dynamic type of that component
   otherwise.

This patch updates the code to make use of the user defined assignment for
allocatable component and make sure the component is allocated correctly.

Reviewed By: klausler

Differential Revision: https://reviews.llvm.org/D147797
flang/runtime/assign.cpp