Skip to content

Commit a9c31b9

Browse files
committed
[DestroyAddrHoisting] Don't destructure NC aggs.
When hoisting destroys of aggregates, an attempt is made to fold the destroys of individual fields into the foregoing instructions. If the aggregate is noncopyable, this transformation is illegal.
1 parent f5a16e4 commit a9c31b9

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

lib/SIL/Utils/MemAccessUtils.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1461,7 +1461,8 @@ bool swift::visitProductLeafAccessPathNodes(
14611461
visitor(AccessPath::PathNode(node), silType);
14621462
continue;
14631463
}
1464-
if (decl->isCxxNonTrivial() || !silType.isEscapable(function)) {
1464+
if (decl->isCxxNonTrivial() || !silType.isEscapable(function) ||
1465+
silType.isMoveOnly()) {
14651466
visitor(AccessPath::PathNode(node), silType);
14661467
continue;
14671468
}

test/SILOptimizer/hoist_destroy_addr.sil

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1255,3 +1255,28 @@ bb0(%aggregate : $*NEAggregate):
12551255
%retval = tuple ()
12561256
return %retval
12571257
}
1258+
1259+
struct NCGutless: ~Copyable {
1260+
let ptr: UnsafeRawPointer?
1261+
}
1262+
struct NCAggregate: ~Copyable {
1263+
var ne: NCGutless
1264+
let regular: Regular
1265+
deinit {}
1266+
}
1267+
1268+
// CHECK-LABEL: sil [ossa] @no_destructure_noncopyable : {{.*}} {
1269+
// CHECK: bb0([[AGGREGATE:%[^,]+]] :
1270+
// CHECK: destroy_addr [[AGGREGATE]]
1271+
// CHECK-LABEL: } // end sil function 'no_destructure_noncopyable'
1272+
sil [ossa] @no_destructure_noncopyable : $@convention(method) (@in NCAggregate) -> () {
1273+
bb0(%aggregate : $*NCAggregate):
1274+
%regular = struct_element_addr %aggregate, #NCAggregate.regular
1275+
%regular_copy = alloc_stack $Regular
1276+
copy_addr %regular to [init] %regular_copy
1277+
destroy_addr %regular_copy
1278+
dealloc_stack %regular_copy
1279+
destroy_addr %aggregate
1280+
%retval = tuple ()
1281+
return %retval
1282+
}

0 commit comments

Comments
 (0)