Skip to content

Commit 2674aef

Browse files
committed
Serialization: Fix crash when deserializing store_unowned SIL instruction
We were casting the operand type to a WeakStorageType when in fact it is an UnownedStorageType. Fixes <rdar://problem/35980211>.
1 parent f2975a8 commit 2674aef

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

lib/Serialization/DeserializeSIL.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1558,7 +1558,7 @@ bool SILDeserializer::readSILInstruction(SILFunction *Fn, SILBasicBlock *BB,
15581558
case SILInstructionKind::StoreUnownedInst: {
15591559
auto Ty = MF->getType(TyID);
15601560
SILType addrType = getSILType(Ty, (SILValueCategory)TyCategory);
1561-
auto refType = addrType.castTo<WeakStorageType>();
1561+
auto refType = addrType.castTo<UnownedStorageType>();
15621562
auto ValType = SILType::getPrimitiveObjectType(refType.getReferentType());
15631563
bool isInit = (Attr > 0);
15641564
ResultVal = Builder.createStoreUnowned(Loc,

test/Serialization/Inputs/def_basic.sil

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1253,6 +1253,31 @@ sil [serialized] [thunk] @a_regular_thunk : $@convention(thin) () -> () {
12531253
return %1 : $()
12541254
}
12551255

1256+
public class WeakUnownedTest {
1257+
@sil_stored public unowned var unownedVal: @sil_unowned AnyObject { get set }
1258+
@sil_stored public weak var weakVal: @sil_weak AnyObject? { get set }
1259+
public init(protoVal: AnyObject)
1260+
deinit
1261+
}
1262+
1263+
// CHECK-LABEL: sil public_external [serialized] @weak_unowned : $@convention(thin) (@owned WeakUnownedTest, @owned AnyObject) -> ()
1264+
sil [serialized] @weak_unowned : $@convention(thin) (@owned WeakUnownedTest, @owned AnyObject) -> () {
1265+
bb0(%0 : $WeakUnownedTest, %1 : $AnyObject):
1266+
%2 = ref_element_addr %0 : $WeakUnownedTest, #WeakUnownedTest.unownedVal
1267+
// CHECK: store_unowned
1268+
store_unowned %1 to %2 : $*@sil_unowned AnyObject
1269+
1270+
%3 = enum $Optional<AnyObject>, #Optional.some!enumelt.1, %1 : $AnyObject
1271+
%4 = ref_element_addr %0 : $WeakUnownedTest, #WeakUnownedTest.weakVal
1272+
// CHECK: store_weak
1273+
store_weak %3 to %4 : $*@sil_weak AnyObject?
1274+
1275+
%r = tuple ()
1276+
1277+
// CHECK: return
1278+
return %r : $()
1279+
}
1280+
12561281
public class Foo {
12571282
subscript (x: Int, y: Int) -> Int32 { get set }
12581283
var x: Int
@@ -1467,6 +1492,7 @@ bb0:
14671492
%150 = function_ref @bridge_object : $@convention(thin) (@owned Class1, Builtin.Word) -> ()
14681493
%151 = function_ref @a_reabstraction_thunk: $@convention(thin) () -> ()
14691494
%152 = function_ref @a_regular_thunk: $@convention(thin) () -> ()
1495+
%153 = function_ref @weak_unowned: $@convention(thin) (@owned WeakUnownedTest, @owned AnyObject) -> ()
14701496

14711497
%r = tuple ()
14721498
return %r : $()

0 commit comments

Comments
 (0)