Skip to content

Commit 3b34264

Browse files
authored
Merge pull request #7990 from gottesmm/use_store_borrow_instead_store_init_for_class_vars_mutableForSet
2 parents 532e20e + 98ad3ea commit 3b34264

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

lib/SILGen/SILGenLValue.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -913,8 +913,12 @@ namespace {
913913
baseFormalType);
914914

915915
baseAddress = gen.emitTemporaryAllocation(loc, base.getType());
916-
gen.B.emitStoreValueOperation(loc, base.getValue(), baseAddress,
917-
StoreOwnershipQualifier::Init);
916+
if (base.getOwnershipKind() == ValueOwnershipKind::Guaranteed) {
917+
gen.B.createStoreBorrow(loc, base.getValue(), baseAddress);
918+
} else {
919+
gen.B.emitStoreValueOperation(loc, base.getValue(), baseAddress,
920+
StoreOwnershipQualifier::Init);
921+
}
918922
}
919923
baseMetatype = gen.B.createMetatype(loc, metatypeType);
920924

test/SILGen/accessors.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func test0(_ ref: A) {
6868
// CHECK-NEXT: [[CALLBACK:%.*]] = pointer_to_thin_function [[CALLBACK_ADDR]] : $Builtin.RawPointer to $@convention(method) (Builtin.RawPointer, @inout Builtin.UnsafeValueBuffer, @inout A, @thick A.Type) -> ()
6969
// CHECK-NEXT: [[TEMP2:%.*]] = alloc_stack $A
7070
// SEMANTIC SIL TODO: This is an issue caused by the callback for materializeForSet in the class case taking the value as @inout when it should really take it as @guaranteed.
71-
// CHECK-NEXT: store [[BORROWED_ARG_LHS]] to [init] [[TEMP2]] : $*A
71+
// CHECK-NEXT: store_borrow [[BORROWED_ARG_LHS]] to [[TEMP2]] : $*A
7272
// CHECK-NEXT: [[T0:%.*]] = metatype $@thick A.Type
7373
// CHECK-NEXT: [[T1:%.*]] = address_to_pointer [[ADDR]] : $*OrdinarySub to $Builtin.RawPointer
7474
// CHECK-NEXT: apply [[CALLBACK]]([[T1]], [[STORAGE]], [[TEMP2]], [[T0]])
@@ -130,7 +130,7 @@ func test1(_ ref: B) {
130130
// CHECK: [[WRITEBACK]]([[CALLBACK_ADDR:%.*]] : $Builtin.RawPointer):
131131
// CHECK-NEXT: [[CALLBACK:%.*]] = pointer_to_thin_function [[CALLBACK_ADDR]] : $Builtin.RawPointer to $@convention(method) (Builtin.RawPointer, @inout Builtin.UnsafeValueBuffer, @inout B, @thick B.Type) -> ()
132132
// CHECK-NEXT: [[TEMP2:%.*]] = alloc_stack $B
133-
// CHECK-NEXT: store [[BORROWED_ARG_RHS]] to [init] [[TEMP2]] : $*B
133+
// CHECK-NEXT: store_borrow [[BORROWED_ARG_RHS]] to [[TEMP2]] : $*B
134134
// CHECK-NEXT: [[T0:%.*]] = metatype $@thick B.Type
135135
// CHECK-NEXT: [[T1:%.*]] = address_to_pointer [[ADDR]] : $*MutatingSub to $Builtin.RawPointer
136136
// CHECK-NEXT: apply [[CALLBACK]]([[T1]], [[STORAGE]], [[TEMP2]], [[T0]])
@@ -156,7 +156,7 @@ func test1(_ ref: B) {
156156
// CHECK: [[WRITEBACK]]([[CALLBACK_ADDR:%.*]] : $Builtin.RawPointer):
157157
// CHECK-NEXT: [[CALLBACK:%.*]] = pointer_to_thin_function [[CALLBACK_ADDR]] : $Builtin.RawPointer to $@convention(method) (Builtin.RawPointer, @inout Builtin.UnsafeValueBuffer, @inout B, @thick B.Type) -> ()
158158
// CHECK-NEXT: [[TEMP2:%.*]] = alloc_stack $B
159-
// CHECK-NEXT: store [[BORROWED_ARG_LHS]] to [init] [[TEMP2]] : $*B
159+
// CHECK-NEXT: store_borrow [[BORROWED_ARG_LHS]] to [[TEMP2]] : $*B
160160
// CHECK-NEXT: [[T0:%.*]] = metatype $@thick B.Type
161161
// CHECK-NEXT: [[T1:%.*]] = address_to_pointer [[ADDR]] : $*MutatingSub to $Builtin.RawPointer
162162
// CHECK-NEXT: apply [[CALLBACK]]([[T1]], [[STORAGE2]], [[TEMP2]], [[T0]])

0 commit comments

Comments
 (0)