Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions lib/SIL/Utils/FieldSensitivePrunedLiveness.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@ TypeSubElementCount::TypeSubElementCount(SILType type, SILModule &mod,
type.getFieldType(fieldDecl, mod, context), mod, context);
number = numElements;

// If we do not have any elements, just set our size to 1.
if (number == 0)
number = 1;
if (type.isValueTypeWithDeinit()) {
// 'self' has its own liveness represented as an additional field at the
// end of the structure.
++number;
}
// If we do not have any elements, just set our size to 1.
if (number == 0)
number = 1;

return;
}
Expand Down Expand Up @@ -450,6 +450,9 @@ void TypeTreeLeafTypeRange::constructFilteredProjections(
callback(newValue, TypeTreeLeafTypeRange(start, next), NeedsDestroy);
start = next;
}
if (start == 0) {
++start;
}
if (type.isValueTypeWithDeinit()) {
// 'self' has its own liveness
++start;
Expand Down
33 changes: 33 additions & 0 deletions test/SILOptimizer/moveonly_addresschecker_unmaximized.sil
Original file line number Diff line number Diff line change
Expand Up @@ -202,3 +202,36 @@ bb0(%s_addr : $*S):
%retval = tuple ()
return %retval : $()
}

sil @getter : $@convention(thin) (@guaranteed M) -> @owned String
sil @die : $@convention(thin) (@guaranteed @noescape @callee_guaranteed () -> @owned String) -> Never

// CHECK-LABEL: sil [ossa] @partial_apply_of_borrow_of_deinitless_empty_struct : {{.*}} {
// CHECK: bb0([[M_IN:%[^,]+]] :
// CHECK: [[STACK:%[^,]+]] = alloc_stack $M
// CHECK: store [[M_IN]] to [init] [[STACK]]
// CHECK: [[ADDR:%[^,]+]] = drop_deinit [[STACK]]
// CHECK: [[MB:%[^,]+]] = load_borrow [[ADDR]]
// CHECK: [[GETTER:%[^,]+]] = function_ref @getter
// CHECK: [[PA:%[^,]+]] = partial_apply [callee_guaranteed] [on_stack] [[GETTER]]([[MB]])
// CHECK: [[DIE:%[^,]+]] = function_ref @die
// CHECK: apply [[DIE]]([[PA]])
// CHECK: destroy_value [[PA]]
// CHECK: end_borrow [[MB]]
// CHECK: unreachable
// CHECK-LABEL: } // end sil function 'partial_apply_of_borrow_of_deinitless_empty_struct'
sil [ossa] @partial_apply_of_borrow_of_deinitless_empty_struct : $@convention(method) (@owned M) -> () {
bb0(%m_in : @owned $M):
%stack = alloc_stack $M
%addr1 = mark_unresolved_non_copyable_value [consumable_and_assignable] %stack : $*M
store %m_in to [init] %addr1 : $*M
%nodeinit = drop_deinit %addr1 : $*M
%addr = mark_unresolved_non_copyable_value [no_consume_or_assign] %nodeinit : $*M
%m = load [copy] %addr : $*M
%mb = begin_borrow %m : $M
%getter = function_ref @getter : $@convention(thin) (@guaranteed M) -> @owned String
%pa = partial_apply [callee_guaranteed] [on_stack] %getter(%mb) : $@convention(thin) (@guaranteed M) -> @owned String
%die = function_ref @die : $@convention(thin) (@guaranteed @noescape @callee_guaranteed () -> @owned String) -> Never
apply %die(%pa) : $@convention(thin) (@guaranteed @noescape @callee_guaranteed () -> @owned String) -> Never
unreachable
}
2 changes: 1 addition & 1 deletion validation-test/SILOptimizer/gh68328.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// REQUIRES: executable_test

struct Example: ~Copyable {
private var failureString: String = "Goodbye."
private var failureString: String { "Goodbye." }
deinit { fatalError("FATAL ERROR: \(failureString)") }
}

Expand Down