Skip to content

Commit

Permalink
[flang][runtime] Initialize LHS temporary in AssignTemporary.
Browse files Browse the repository at this point in the history
If LHS is of derived type that needs initialization, then it must be
initialized before doing the assignment. Otherwise, the assignment
might behave incorrectly based on uninitialized components that are
descriptors themselves.

Differential Revision: https://reviews.llvm.org/D149681
  • Loading branch information
vzakhari committed May 3, 2023
1 parent 13441eb commit 1aff61e
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions flang/runtime/assign.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,17 @@ void RTNAME(Assign)(Descriptor &to, const Descriptor &from,
void RTNAME(AssignTemporary)(Descriptor &to, const Descriptor &from,
const char *sourceFile, int sourceLine) {
Terminator terminator{sourceFile, sourceLine};
// Initialize the "to" if it is of derived type that needs initialization.
if (const DescriptorAddendum * addendum{to.Addendum()}) {
if (const auto *derived{addendum->derivedType()}) {
if (!derived->noInitializationNeeded()) {
if (ReturnError(terminator, Initialize(to, *derived, terminator)) !=
StatOk) {
return;
}
}
}
}
Assign(to, from, terminator, PolymorphicLHS);
}

Expand Down

0 comments on commit 1aff61e

Please sign in to comment.