Skip to content

Commit 417036e

Browse files
clementvalgysit
authored andcommitted
[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
1 parent 2425566 commit 417036e

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

flang/runtime/assign.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -381,10 +381,7 @@ static void Assign(
381381
// when the components are polymorphic; when they're not, they're both
382382
// not, and their declared types will match.
383383
int nestedFlags{MaybeReallocate | PolymorphicLHS};
384-
if (comp.genre() != typeInfo::Component::Genre::Allocatable &&
385-
(flags & ComponentCanBeDefinedAssignment)) {
386-
// Allocatable components are assigned via intrinsic assignment,
387-
// not defined assignment (see F'2018 10.2.1.3 paragraph 13).
384+
if (flags & ComponentCanBeDefinedAssignment) {
388385
nestedFlags |= CanBeDefinedAssignment | ComponentCanBeDefinedAssignment;
389386
}
390387
switch (comp.genre()) {
@@ -442,6 +439,15 @@ static void Assign(
442439
if (!fromDesc->IsAllocated()) {
443440
continue; // F'2018 10.2.1.3(13)(2)
444441
}
442+
443+
// F'2018 10.2.1.3(13) (2)
444+
// If from is allocated, allocate to with the same type.
445+
if (nestedFlags & CanBeDefinedAssignment) {
446+
if (AllocateAssignmentLHS(
447+
*toDesc, *fromDesc, terminator, nestedFlags) != StatOk) {
448+
return;
449+
}
450+
}
445451
}
446452
Assign(*toDesc, *fromDesc, terminator, nestedFlags);
447453
}

0 commit comments

Comments
 (0)