Skip to content

Commit eac5f83

Browse files
committed
SILGen: Don't crash on withoutActuallyEscaping of objc blocks
rdar://38689227
1 parent 19d3a4d commit eac5f83

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

lib/SILGen/SILGenExpr.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5480,6 +5480,28 @@ RValue RValueEmitter::visitMakeTemporarilyEscapableExpr(
54805480
visit(E->getNonescapingClosureValue()).getAsSingleValue(SGF, E);
54815481

54825482
auto escapingFnTy = SGF.getLoweredType(E->getOpaqueValue()->getType());
5483+
auto silFnTy = escapingFnTy.castTo<SILFunctionType>();
5484+
5485+
// Handle @convention(block). No withoutActuallyEscaping verification yet.
5486+
if (silFnTy->getExtInfo().getRepresentation() !=
5487+
SILFunctionTypeRepresentation::Thick) {
5488+
RValue rvalue;
5489+
auto escapingClosure =
5490+
SGF.emitManagedRValueWithCleanup(SGF.B.createConvertFunction(
5491+
E, functionValue.ensurePlusOne(SGF, E).forward(SGF), escapingFnTy));
5492+
// Bind the opaque value to the escaping function.
5493+
SILGenFunction::OpaqueValueState opaqueValue{
5494+
escapingClosure,
5495+
/*consumable*/ true,
5496+
/*hasBeenConsumed*/ false,
5497+
};
5498+
SILGenFunction::OpaqueValueRAII pushOpaqueValue(SGF, E->getOpaqueValue(),
5499+
opaqueValue);
5500+
5501+
// Emit the guarded expression.
5502+
rvalue = visit(E->getSubExpr(), C);
5503+
return rvalue;
5504+
}
54835505

54845506
// Convert it to an escaping function value.
54855507
auto escapingClosure =

0 commit comments

Comments
 (0)