[sil-devirtualizer] Fix a bug in devirtualization of methods that never return

This bug was caught by the SIL verifier. Any invocation of a NoReturn function should be followed by an `unreachable` instruction.

Fixes rdar://problem/33591235
This commit is contained in:
Roman Levenstein
2017-08-02 15:14:03 -07:00
parent efb3c5072c
commit b83faa0109
3 changed files with 86 additions and 4 deletions

View File

@@ -150,10 +150,15 @@ static FullApplySite speculateMonomorphicTarget(FullApplySite AI,
SILArgument *Arg =
Continue->createPHIArgument(AI.getType(), ValueOwnershipKind::Owned);
if (!isa<TryApplyInst>(AI)) {
IdenBuilder.createBranch(AI.getLoc(), Continue,
ArrayRef<SILValue>(IdenAI.getInstruction()));
VirtBuilder.createBranch(AI.getLoc(), Continue,
ArrayRef<SILValue>(VirtAI.getInstruction()));
if (AI.getSubstCalleeType()->isNoReturnFunction()) {
IdenBuilder.createUnreachable(AI.getLoc());
VirtBuilder.createUnreachable(AI.getLoc());
} else {
IdenBuilder.createBranch(AI.getLoc(), Continue,
ArrayRef<SILValue>(IdenAI.getInstruction()));
VirtBuilder.createBranch(AI.getLoc(), Continue,
ArrayRef<SILValue>(VirtAI.getInstruction()));
}
}
// Remove the old Apply instruction.