Skip to content

Commit 1a0a44c

Browse files
Merge pull request #73174 from nate-chandler/rdar126863003
[MoveOnlyAddressChecker] Fix empty deiniting struct representation.
2 parents e4ac42b + 5325a4d commit 1a0a44c

File tree

3 files changed

+40
-4
lines changed

3 files changed

+40
-4
lines changed

lib/SIL/Utils/FieldSensitivePrunedLiveness.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,14 @@ TypeSubElementCount::TypeSubElementCount(SILType type, SILModule &mod,
7171
type.getFieldType(fieldDecl, mod, context), mod, context);
7272
number = numElements;
7373

74+
// If we do not have any elements, just set our size to 1.
75+
if (number == 0)
76+
number = 1;
7477
if (type.isValueTypeWithDeinit()) {
7578
// 'self' has its own liveness represented as an additional field at the
7679
// end of the structure.
7780
++number;
7881
}
79-
// If we do not have any elements, just set our size to 1.
80-
if (number == 0)
81-
number = 1;
8282

8383
return;
8484
}
@@ -450,6 +450,9 @@ void TypeTreeLeafTypeRange::constructFilteredProjections(
450450
callback(newValue, TypeTreeLeafTypeRange(start, next), NeedsDestroy);
451451
start = next;
452452
}
453+
if (start == 0) {
454+
++start;
455+
}
453456
if (type.isValueTypeWithDeinit()) {
454457
// 'self' has its own liveness
455458
++start;

test/SILOptimizer/moveonly_addresschecker_unmaximized.sil

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,3 +202,36 @@ bb0(%s_addr : $*S):
202202
%retval = tuple ()
203203
return %retval : $()
204204
}
205+
206+
sil @getter : $@convention(thin) (@guaranteed M) -> @owned String
207+
sil @die : $@convention(thin) (@guaranteed @noescape @callee_guaranteed () -> @owned String) -> Never
208+
209+
// CHECK-LABEL: sil [ossa] @partial_apply_of_borrow_of_deinitless_empty_struct : {{.*}} {
210+
// CHECK: bb0([[M_IN:%[^,]+]] :
211+
// CHECK: [[STACK:%[^,]+]] = alloc_stack $M
212+
// CHECK: store [[M_IN]] to [init] [[STACK]]
213+
// CHECK: [[ADDR:%[^,]+]] = drop_deinit [[STACK]]
214+
// CHECK: [[MB:%[^,]+]] = load_borrow [[ADDR]]
215+
// CHECK: [[GETTER:%[^,]+]] = function_ref @getter
216+
// CHECK: [[PA:%[^,]+]] = partial_apply [callee_guaranteed] [on_stack] [[GETTER]]([[MB]])
217+
// CHECK: [[DIE:%[^,]+]] = function_ref @die
218+
// CHECK: apply [[DIE]]([[PA]])
219+
// CHECK: destroy_value [[PA]]
220+
// CHECK: end_borrow [[MB]]
221+
// CHECK: unreachable
222+
// CHECK-LABEL: } // end sil function 'partial_apply_of_borrow_of_deinitless_empty_struct'
223+
sil [ossa] @partial_apply_of_borrow_of_deinitless_empty_struct : $@convention(method) (@owned M) -> () {
224+
bb0(%m_in : @owned $M):
225+
%stack = alloc_stack $M
226+
%addr1 = mark_unresolved_non_copyable_value [consumable_and_assignable] %stack : $*M
227+
store %m_in to [init] %addr1 : $*M
228+
%nodeinit = drop_deinit %addr1 : $*M
229+
%addr = mark_unresolved_non_copyable_value [no_consume_or_assign] %nodeinit : $*M
230+
%m = load [copy] %addr : $*M
231+
%mb = begin_borrow %m : $M
232+
%getter = function_ref @getter : $@convention(thin) (@guaranteed M) -> @owned String
233+
%pa = partial_apply [callee_guaranteed] [on_stack] %getter(%mb) : $@convention(thin) (@guaranteed M) -> @owned String
234+
%die = function_ref @die : $@convention(thin) (@guaranteed @noescape @callee_guaranteed () -> @owned String) -> Never
235+
apply %die(%pa) : $@convention(thin) (@guaranteed @noescape @callee_guaranteed () -> @owned String) -> Never
236+
unreachable
237+
}

validation-test/SILOptimizer/gh68328.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
// REQUIRES: executable_test
88

99
struct Example: ~Copyable {
10-
private var failureString: String = "Goodbye."
10+
private var failureString: String { "Goodbye." }
1111
deinit { fatalError("FATAL ERROR: \(failureString)") }
1212
}
1313

0 commit comments

Comments
 (0)