[flang-commits] [flang] 3acdd59 - [flang] Handle correctly user defined assignment for allocatable component
Valentin Clement via flang-commits
flang-commits at lists.llvm.org
Fri Apr 7 11:48:00 PDT 2023
Author: Valentin Clement
Date: 2023-04-07T11:47:54-07:00
New Revision: 3acdd596c0d7a51038f1be4a9bbc86ba288301ba
URL: https://github.com/llvm/llvm-project/commit/3acdd596c0d7a51038f1be4a9bbc86ba288301ba
DIFF: https://github.com/llvm/llvm-project/commit/3acdd596c0d7a51038f1be4a9bbc86ba288301ba.diff
LOG: [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
Added:
Modified:
flang/runtime/assign.cpp
Removed:
################################################################################
diff --git a/flang/runtime/assign.cpp b/flang/runtime/assign.cpp
index b4d9061846e9d..095c4d3b9eefd 100644
--- a/flang/runtime/assign.cpp
+++ b/flang/runtime/assign.cpp
@@ -381,10 +381,7 @@ static void Assign(
// when the components are polymorphic; when they're not, they're both
// not, and their declared types will match.
int nestedFlags{MaybeReallocate | PolymorphicLHS};
- if (comp.genre() != typeInfo::Component::Genre::Allocatable &&
- (flags & ComponentCanBeDefinedAssignment)) {
- // Allocatable components are assigned via intrinsic assignment,
- // not defined assignment (see F'2018 10.2.1.3 paragraph 13).
+ if (flags & ComponentCanBeDefinedAssignment) {
nestedFlags |= CanBeDefinedAssignment | ComponentCanBeDefinedAssignment;
}
switch (comp.genre()) {
@@ -442,6 +439,15 @@ static void Assign(
if (!fromDesc->IsAllocated()) {
continue; // F'2018 10.2.1.3(13)(2)
}
+
+ // F'2018 10.2.1.3(13) (2)
+ // If from is allocated, allocate to with the same type.
+ if (nestedFlags & CanBeDefinedAssignment) {
+ if (AllocateAssignmentLHS(
+ *toDesc, *fromDesc, terminator, nestedFlags) != StatOk) {
+ return;
+ }
+ }
}
Assign(*toDesc, *fromDesc, terminator, nestedFlags);
}
More information about the flang-commits
mailing list