Skip to content

Commit da3e477

Browse files
committed
[flang] Avoid double finalization in Assign
First call to Assign is issuing finalization for the LHS and its components. Avoid calling finalization for components again when doing the component by component assignment. Reviewed By: klausler Differential Revision: https://reviews.llvm.org/D143187
1 parent fe08212 commit da3e477

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

flang/runtime/assign.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ static void DoElementalDefinedAssignment(const Descriptor &to,
6868
// Do not perform allocatable reallocation if \p skipRealloc is true, which is
6969
// used for allocate statement with source specifier.
7070
static void Assign(Descriptor &to, const Descriptor &from,
71-
Terminator &terminator, bool skipRealloc = false) {
71+
Terminator &terminator, bool skipRealloc = false,
72+
bool skipFinalization = false) {
7273
DescriptorAddendum *toAddendum{to.Addendum()};
7374
const typeInfo::DerivedType *toDerived{
7475
toAddendum ? toAddendum->derivedType() : nullptr};
@@ -184,7 +185,8 @@ static void Assign(Descriptor &to, const Descriptor &from,
184185
// Derived type intrinsic assignment, which is componentwise and elementwise
185186
// for all components, including parent components (10.2.1.2-3).
186187
// The target is first finalized if still necessary (7.5.6.3(1))
187-
if (!wasJustAllocated && !toDerived->noFinalizationNeeded()) {
188+
if (!wasJustAllocated && !toDerived->noFinalizationNeeded() &&
189+
!skipFinalization) {
188190
Finalize(to, *toDerived);
189191
}
190192
// Copy the data components (incl. the parent) first.
@@ -205,7 +207,8 @@ static void Assign(Descriptor &to, const Descriptor &from,
205207
comp.CreatePointerDescriptor(toCompDesc, to, terminator, toAt);
206208
comp.CreatePointerDescriptor(
207209
fromCompDesc, from, terminator, fromAt);
208-
Assign(toCompDesc, fromCompDesc, terminator, /*skipRealloc=*/false);
210+
Assign(toCompDesc, fromCompDesc, terminator, /*skipRealloc=*/false,
211+
/*skipFinalization=*/true);
209212
}
210213
} else { // Component has intrinsic type; simply copy raw bytes
211214
std::size_t componentByteSize{comp.SizeInBytes(to)};

0 commit comments

Comments
 (0)