Skip to content

Commit 10db94e

Browse files
committed
[silgen] When checking we check if a failable initializer that we delegated to returned null, reload self using the normal semantics.
We have already finished the delegation sequence at this point, so we should go through normal semantics. rdar://33358110
1 parent f23a499 commit 10db94e

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

lib/SILGen/SILGenExpr.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3473,8 +3473,20 @@ RValue RValueEmitter::visitRebindSelfInConstructorExpr(
34733473
!calledCtor->isImplicit() &&
34743474
usesObjCAllocator(classDecl)) {
34753475

3476-
// Check whether the new self is null.
3477-
SILValue isNonnullSelf = SGF.B.createIsNonnull(E, newSelf.getValue());
3476+
// Check whether the new self is null. *NOTE* At this point, we can not
3477+
// access the actual new value using newSelf anymore. We need to grab self
3478+
// via the normal manner of doing so.
3479+
SILValue isNonnullSelf;
3480+
{
3481+
Scope S(SGF, E);
3482+
RValue selfRValue =
3483+
SGF.emitRValueForDecl(E, selfDecl, selfTy->getCanonicalType(),
3484+
AccessSemantics::DirectToStorage,
3485+
SGFContext::AllowGuaranteedPlusZero);
3486+
ManagedValue reloadedSelf =
3487+
std::move(selfRValue).getAsSingleValue(SGF, E);
3488+
isNonnullSelf = SGF.B.createIsNonnull(E, reloadedSelf.getValue());
3489+
}
34783490
Condition cond = SGF.emitCondition(isNonnullSelf, E,
34793491
/*hasFalseCode=*/false,
34803492
/*invertValue=*/true,

test/SILGen/objc_thunks.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,9 @@ extension Hoozit {
427427
// CHECK: [[CTOR:%[0-9]+]] = class_method [volatile] [[SELF:%[0-9]+]] : $Hoozit, #Hoozit.init!initializer.1.foreign : (Hoozit.Type) -> (Int) -> Hoozit, $@convention(objc_method) (Int, @owned Hoozit) -> @owned Hoozit
428428
// CHECK: [[NEW_SELF:%[0-9]+]] = apply [[CTOR]]
429429
// CHECK: store [[NEW_SELF]] to [init] [[PB_BOX]] : $*Hoozit
430-
// CHECK: [[NONNULL:%[0-9]+]] = is_nonnull [[NEW_SELF]] : $Hoozit
430+
// CHECK: [[RELOADED_SELF:%.*]] = load_borrow [[PB_BOX]]
431+
// CHECK: [[NONNULL:%[0-9]+]] = is_nonnull [[RELOADED_SELF]] : $Hoozit
432+
// CHECK: end_borrow [[RELOADED_SELF]] from [[PB_BOX]]
431433
// CHECK-NEXT: cond_br [[NONNULL]], [[NONNULL_BB:bb[0-9]+]], [[NULL_BB:bb[0-9]+]]
432434
// CHECK: [[NULL_BB]]:
433435
// CHECK-NEXT: destroy_value [[X_BOX]] : ${ var X }

0 commit comments

Comments
 (0)