diff --git a/flang/runtime/assign.cpp b/flang/runtime/assign.cpp index d558ada51cd21..5c2ea2e416283 100644 --- a/flang/runtime/assign.cpp +++ b/flang/runtime/assign.cpp @@ -155,9 +155,9 @@ static RT_API_ATTRS bool MayAlias(const Descriptor &x, const Descriptor &y) { return false; // not both allocated } const char *xDesc{reinterpret_cast(&x)}; - const char *xDescLast{xDesc + x.SizeInBytes()}; + const char *xDescLast{xDesc + x.SizeInBytes() - 1}; const char *yDesc{reinterpret_cast(&y)}; - const char *yDescLast{yDesc + y.SizeInBytes()}; + const char *yDescLast{yDesc + y.SizeInBytes() - 1}; std::int64_t xLeast, xMost, yLeast, yMost; MaximalByteOffsetRange(x, xLeast, xMost); MaximalByteOffsetRange(y, yLeast, yMost); @@ -318,10 +318,8 @@ RT_API_ATTRS static void Assign( if (mustDeallocateLHS) { if (deferDeallocation) { if ((flags & NeedFinalization) && toDerived) { - Finalize(to, *toDerived, &terminator); + Finalize(*deferDeallocation, *toDerived, &terminator); flags &= ~NeedFinalization; - } else if (toDerived && !toDerived->noDestructionNeeded()) { - Destroy(to, /*finalize=*/false, *toDerived, &terminator); } } else { to.Destroy((flags & NeedFinalization) != 0, /*destroyPointers=*/false,