Skip to content

Commit f5a16e4

Browse files
committed
[DestroyAddrHoisting] Don't destructure NE 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 nonescapable, this transformation is illegal. rdar://152195094
1 parent f7ca26c commit f5a16e4

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

lib/SIL/Utils/MemAccessUtils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1461,7 +1461,7 @@ bool swift::visitProductLeafAccessPathNodes(
14611461
visitor(AccessPath::PathNode(node), silType);
14621462
continue;
14631463
}
1464-
if (decl->isCxxNonTrivial()) {
1464+
if (decl->isCxxNonTrivial() || !silType.isEscapable(function)) {
14651465
visitor(AccessPath::PathNode(node), silType);
14661466
continue;
14671467
}

test/SILOptimizer/hoist_destroy_addr.sil

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
// RUN: %target-sil-opt -sil-print-types -opt-mode=none -enable-sil-verify-all %s -compute-side-effects -destroy-addr-hoisting | %FileCheck %s --check-prefix=CHECK --check-prefix=CHECKDEB --check-prefix=CHECK-DEB
2-
// RUN: %target-sil-opt -sil-print-types -opt-mode=speed -enable-sil-verify-all %s -compute-side-effects -destroy-addr-hoisting | %FileCheck %s --check-prefix=CHECK --check-prefix=CHECKOPT --check-prefix=CHECK-OPT
1+
// RUN: %target-sil-opt -sil-print-types -enable-experimental-feature LifetimeDependence -opt-mode=none -enable-sil-verify-all %s -compute-side-effects -destroy-addr-hoisting | %FileCheck %s --check-prefix=CHECK --check-prefix=CHECKDEB --check-prefix=CHECK-DEB
2+
// RUN: %target-sil-opt -sil-print-types -enable-experimental-feature LifetimeDependence -opt-mode=speed -enable-sil-verify-all %s -compute-side-effects -destroy-addr-hoisting | %FileCheck %s --check-prefix=CHECK --check-prefix=CHECKOPT --check-prefix=CHECK-OPT
33
//
44
// TODO: migrate the remaining tests from destroy_hoisting.sil.
55

66
// REQUIRES: swift_in_compiler
7+
// REQUIRES: swift_feature_LifetimeDependence
78

89
sil_stage canonical
910

@@ -1224,3 +1225,33 @@ bb0(%0 : @owned $Nontrivial):
12241225
%14 = tuple ()
12251226
return %14 : $()
12261227
}
1228+
1229+
struct Regular {
1230+
var storage: Builtin.NativeObject
1231+
}
1232+
struct NEGutless: ~Escapable {
1233+
let ptr: UnsafeRawPointer?
1234+
}
1235+
struct NEMarker : ~Escapable {}
1236+
struct NEAggregate: ~Escapable {
1237+
var ne: NEGutless
1238+
let regular: Regular
1239+
1240+
@lifetime(copy ne) init(ne: NEMarker)
1241+
}
1242+
1243+
// CHECK-LABEL: sil [ossa] @no_destructure_nonescapable : {{.*}} {
1244+
// CHECK: bb0([[AGGREGATE:%[^,]+]] :
1245+
// CHECK: destroy_addr [[AGGREGATE]]
1246+
// CHECK-LABEL: } // end sil function 'no_destructure_nonescapable'
1247+
sil [ossa] @no_destructure_nonescapable : $@convention(method) (@in NEAggregate) -> () {
1248+
bb0(%aggregate : $*NEAggregate):
1249+
%regular = struct_element_addr %aggregate, #NEAggregate.regular
1250+
%regular_copy = alloc_stack $Regular
1251+
copy_addr %regular to [init] %regular_copy
1252+
destroy_addr %regular_copy
1253+
dealloc_stack %regular_copy
1254+
destroy_addr %aggregate
1255+
%retval = tuple ()
1256+
return %retval
1257+
}

0 commit comments

Comments
 (0)