Skip to content

Commit 6822ad9

Browse files
Merge pull request #73178 from nate-chandler/cherrypick/release/6.0/rdar126863003
6.0: [MoveOnlyAddressChecker] Fix empty deiniting struct representation.
2 parents 41308c1 + 74a2c76 commit 6822ad9

File tree

3 files changed

+41
-4
lines changed

3 files changed

+41
-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: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// RUN: | %FileCheck %s
99

1010
import Builtin
11+
import Swift
1112

1213
@_moveOnly
1314
struct M {
@@ -203,3 +204,36 @@ bb0(%s_addr : $*S):
203204
%retval = tuple ()
204205
return %retval : $()
205206
}
207+
208+
sil @getter : $@convention(thin) (@guaranteed M) -> @owned String
209+
sil @die : $@convention(thin) (@guaranteed @noescape @callee_guaranteed () -> @owned String) -> Never
210+
211+
// CHECK-LABEL: sil [ossa] @partial_apply_of_borrow_of_deinitless_empty_struct : {{.*}} {
212+
// CHECK: bb0([[M_IN:%[^,]+]] :
213+
// CHECK: [[STACK:%[^,]+]] = alloc_stack $M
214+
// CHECK: store [[M_IN]] to [init] [[STACK]]
215+
// CHECK: [[ADDR:%[^,]+]] = drop_deinit [[STACK]]
216+
// CHECK: [[MB:%[^,]+]] = load_borrow [[ADDR]]
217+
// CHECK: [[GETTER:%[^,]+]] = function_ref @getter
218+
// CHECK: [[PA:%[^,]+]] = partial_apply [callee_guaranteed] [on_stack] [[GETTER]]([[MB]])
219+
// CHECK: [[DIE:%[^,]+]] = function_ref @die
220+
// CHECK: apply [[DIE]]([[PA]])
221+
// CHECK: destroy_value [[PA]]
222+
// CHECK: end_borrow [[MB]]
223+
// CHECK: unreachable
224+
// CHECK-LABEL: } // end sil function 'partial_apply_of_borrow_of_deinitless_empty_struct'
225+
sil [ossa] @partial_apply_of_borrow_of_deinitless_empty_struct : $@convention(method) (@owned M) -> () {
226+
bb0(%m_in : @owned $M):
227+
%stack = alloc_stack $M
228+
%addr1 = mark_unresolved_non_copyable_value [consumable_and_assignable] %stack : $*M
229+
store %m_in to [init] %addr1 : $*M
230+
%nodeinit = drop_deinit %addr1 : $*M
231+
%addr = mark_unresolved_non_copyable_value [no_consume_or_assign] %nodeinit : $*M
232+
%m = load [copy] %addr : $*M
233+
%mb = begin_borrow %m : $M
234+
%getter = function_ref @getter : $@convention(thin) (@guaranteed M) -> @owned String
235+
%pa = partial_apply [callee_guaranteed] [on_stack] %getter(%mb) : $@convention(thin) (@guaranteed M) -> @owned String
236+
%die = function_ref @die : $@convention(thin) (@guaranteed @noescape @callee_guaranteed () -> @owned String) -> Never
237+
apply %die(%pa) : $@convention(thin) (@guaranteed @noescape @callee_guaranteed () -> @owned String) -> Never
238+
unreachable
239+
}

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)