Skip to content

Commit ea82df3

Browse files
authored
Merge pull request #39722 from nate-chandler/lexical_lifetimes/only-owned-or-guaranteed-arg-conventions-when-inlining
2 parents 81afe50 + 09dd182 commit ea82df3

File tree

2 files changed

+136
-59
lines changed

2 files changed

+136
-59
lines changed

lib/SILOptimizer/Utils/SILInliner.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -601,9 +601,18 @@ SILValue SILInlineCloner::borrowFunctionArgument(SILValue callArg,
601601
->getModule()
602602
.getASTContext()
603603
.SILOpts.EnableExperimentalLexicalLifetimes;
604-
if (!AI.getFunction()->hasOwnership() ||
605-
(callArg.getOwnershipKind() != OwnershipKind::Owned &&
606-
!enableLexicalLifetimes)) {
604+
auto argOwnershipRequiresBorrow = [&]() {
605+
auto kind = callArg.getOwnershipKind();
606+
if (enableLexicalLifetimes) {
607+
// At this point, we know that the function argument is @guaranteed.
608+
// If the value passed as that parameter has ownership, always add a
609+
// lexical borrow scope to ensure that the value stays alive for the
610+
// duration of the inlined callee.
611+
return kind != OwnershipKind::None;
612+
}
613+
return kind == OwnershipKind::Owned;
614+
};
615+
if (!AI.getFunction()->hasOwnership() || !argOwnershipRequiresBorrow()) {
607616
return SILValue();
608617
}
609618

0 commit comments

Comments
 (0)