Skip to content

Commit 8a8fdd8

Browse files
committed
Fix a use-after-free in MandatoryInlining.
Bug introduced in @NoEscape lowering: #12420 Fixes <rdar://problem/35055251> FAILED: ASAN use-after-free in MandatoryInlining.
1 parent 379afbd commit 8a8fdd8

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

lib/SILOptimizer/Mandatory/MandatoryInlining.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,10 @@ cleanupCalleeValue(SILValue CalleeValue, ArrayRef<SILValue> CaptureArgs,
182182
}
183183

184184
SILValue CalleeSource = CalleeValue;
185+
// Handle partial_apply/thin_to_thick -> convert_function:
186+
// tryDeleteDeadClosure must run before deleting a ConvertFunction that
187+
// uses the PartialApplyInst or ThinToThickFunctionInst. tryDeleteDeadClosure
188+
// will delete any uses of the closure, including this ConvertFunction.
185189
if (auto *CFI = dyn_cast<ConvertFunctionInst>(CalleeValue))
186190
CalleeSource = CFI->getOperand();
187191

@@ -190,15 +194,15 @@ cleanupCalleeValue(SILValue CalleeValue, ArrayRef<SILValue> CaptureArgs,
190194
if (!tryDeleteDeadClosure(PAI))
191195
return;
192196
CalleeValue = Callee;
193-
}
194197

195-
if (auto *TTTFI = dyn_cast<ThinToThickFunctionInst>(CalleeSource)) {
198+
} else if (auto *TTTFI = dyn_cast<ThinToThickFunctionInst>(CalleeSource)) {
196199
SILValue Callee = TTTFI->getCallee();
197200
if (!tryDeleteDeadClosure(TTTFI))
198201
return;
199202
CalleeValue = Callee;
200203
}
201204

205+
// Handle function_ref -> convert_function -> partial_apply/thin_to_thick.
202206
if (auto *CFI = dyn_cast<ConvertFunctionInst>(CalleeValue)) {
203207
if (isInstructionTriviallyDead(CFI)) {
204208
recursivelyDeleteTriviallyDeadInstructions(CFI, true);

0 commit comments

Comments
 (0)