Skip to content

Fix a use-after-free in MandatoryInlining. #12505

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 19, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/SILOptimizer/Mandatory/MandatoryInlining.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,10 @@ cleanupCalleeValue(SILValue CalleeValue, ArrayRef<SILValue> CaptureArgs,
}

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

Expand All @@ -190,15 +194,15 @@ cleanupCalleeValue(SILValue CalleeValue, ArrayRef<SILValue> CaptureArgs,
if (!tryDeleteDeadClosure(PAI))
return;
CalleeValue = Callee;
}

if (auto *TTTFI = dyn_cast<ThinToThickFunctionInst>(CalleeSource)) {
} else if (auto *TTTFI = dyn_cast<ThinToThickFunctionInst>(CalleeSource)) {
SILValue Callee = TTTFI->getCallee();
if (!tryDeleteDeadClosure(TTTFI))
return;
CalleeValue = Callee;
}

// Handle function_ref -> convert_function -> partial_apply/thin_to_thick.
if (auto *CFI = dyn_cast<ConvertFunctionInst>(CalleeValue)) {
if (isInstructionTriviallyDead(CFI)) {
recursivelyDeleteTriviallyDeadInstructions(CFI, true);
Expand Down