Skip to content

Commit 96a183f

Browse files
authored
Merge pull request #65099 from nate-chandler/nfc/20230412/1/assertion-reflow
[TempRValueOpt] NFC: Clarified assertion.
2 parents 2bcef82 + 1938912 commit 96a183f

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

lib/SILOptimizer/Transforms/TempRValueElimination.cpp

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -616,17 +616,23 @@ void TempRValueOptPass::tryOptimizeCopyIntoTemp(CopyAddrInst *copyInst) {
616616
if (lastLoadInst == copyInst)
617617
return true;
618618
if (auto *cai = dyn_cast<CopyAddrInst>(lastLoadInst)) {
619-
auto retval = cai->getSrc() != tempObj || !cai->isTakeOfSrc();
620-
assert(!tempObj->getType().isMoveOnly() ||
621-
!retval && "introducing copy of move-only value!?");
622-
return retval;
619+
if (cai->getSrc() == tempObj && cai->isTakeOfSrc()) {
620+
// This copy_addr [take] will perform the final deinitialization.
621+
return false;
622+
}
623+
assert(!tempObj->getType().isMoveOnly() &&
624+
"introducing copy of move-only value!?");
625+
return true;
623626
}
624627
if (auto *li = dyn_cast<LoadInst>(lastLoadInst)) {
625-
auto retval = li->getOperand() != tempObj ||
626-
li->getOwnershipQualifier() != LoadOwnershipQualifier::Take;
627-
assert(!tempObj->getType().isMoveOnly() ||
628-
!retval && "introducing copy of move-only value!?");
629-
return retval;
628+
if (li->getOperand() == tempObj &&
629+
li->getOwnershipQualifier() == LoadOwnershipQualifier::Take) {
630+
// This load [take] will perform the final deinitialization.
631+
return false;
632+
}
633+
assert(!tempObj->getType().isMoveOnly() &&
634+
"introducing copy of move-only value!?");
635+
return true;
630636
}
631637
return true;
632638
}();

0 commit comments

Comments
 (0)