Skip to content

Commit 0383415

Browse files
committed
[SILInliner] Respect explicit argument lifetimes.
1 parent dc3106f commit 0383415

File tree

2 files changed

+445
-5
lines changed

2 files changed

+445
-5
lines changed

lib/SILOptimizer/Utils/SILInliner.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,8 @@ class SILInlineCloner
286286
void cloneInline(ArrayRef<SILValue> AppliedArgs);
287287

288288
protected:
289-
SILValue borrowFunctionArgument(SILValue callArg, FullApplySite AI);
289+
SILValue borrowFunctionArgument(SILValue callArg, FullApplySite AI,
290+
unsigned index);
290291

291292
void visitDebugValueInst(DebugValueInst *Inst);
292293
void visitHopToExecutorInst(HopToExecutorInst *Inst);
@@ -466,7 +467,7 @@ void SILInlineCloner::cloneInline(ArrayRef<SILValue> AppliedArgs) {
466467
} else {
467468
// Insert begin/end borrow for guaranteed arguments.
468469
if (paramInfo.isGuaranteed()) {
469-
if (SILValue newValue = borrowFunctionArgument(callArg, Apply)) {
470+
if (SILValue newValue = borrowFunctionArgument(callArg, Apply, idx)) {
470471
callArg = newValue;
471472
borrowedArgs[idx] = true;
472473
}
@@ -612,7 +613,8 @@ void SILInlineCloner::postFixUp(SILFunction *calleeFunction) {
612613
}
613614

614615
SILValue SILInlineCloner::borrowFunctionArgument(SILValue callArg,
615-
FullApplySite AI) {
616+
FullApplySite AI,
617+
unsigned index) {
616618
auto &mod = Apply.getFunction()->getModule();
617619
auto enableLexicalLifetimes =
618620
mod.getASTContext().SILOpts.supportsLexicalLifetimes(mod);
@@ -631,9 +633,13 @@ SILValue SILInlineCloner::borrowFunctionArgument(SILValue callArg,
631633
return SILValue();
632634
}
633635

636+
SILFunctionArgument *argument = cast<SILFunctionArgument>(
637+
getCalleeFunction()->getEntryBlock()->getArgument(index));
638+
634639
SILBuilderWithScope beginBuilder(AI.getInstruction(), getBuilder());
635-
return beginBuilder.createBeginBorrow(AI.getLoc(), callArg,
636-
/*isLexical=*/enableLexicalLifetimes);
640+
auto isLexical =
641+
enableLexicalLifetimes && argument->getLifetime().isLexical();
642+
return beginBuilder.createBeginBorrow(AI.getLoc(), callArg, isLexical);
637643
}
638644

639645
void SILInlineCloner::visitDebugValueInst(DebugValueInst *Inst) {

0 commit comments

Comments
 (0)