File tree Expand file tree Collapse file tree 4 files changed +45
-6
lines changed
include/swift/SILOptimizer/Utils Expand file tree Collapse file tree 4 files changed +45
-6
lines changed Original file line number Diff line number Diff line change @@ -370,9 +370,7 @@ class CanonicalizeOSSALifetime final {
370
370
currentDef = def;
371
371
currentLexicalLifetimeEnds = lexicalLifetimeEnds;
372
372
373
- if (maximizeLifetime || respectsDeinitBarriers ()) {
374
- liveness->initializeDiscoveredBlocks (&discoveredBlocks);
375
- }
373
+ liveness->initializeDiscoveredBlocks (&discoveredBlocks);
376
374
liveness->initializeDef (getCurrentDef ());
377
375
}
378
376
Original file line number Diff line number Diff line change @@ -274,6 +274,18 @@ bool CanonicalizeOSSALifetime::computeCanonicalLiveness() {
274
274
return true ;
275
275
}
276
276
277
+ // / Extend liveness to the copy-extended availability boundary of currentDef.
278
+ // / Prevents destroys from being inserted between borrows of (copies of) the
279
+ // / def and dead-ends.
280
+ // /
281
+ // / Example:
282
+ // / %def need not be lexical
283
+ // / %c = copy_value %def
284
+ // / %sb = store_borrow %c to %addr
285
+ // / // Must extend lifetime of %def up to this point. Otherwise, a
286
+ // / // destroy_value could be inserted within a borrow scope or interior
287
+ // / // pointer use.
288
+ // / unreachable
277
289
void CanonicalizeOSSALifetime::extendLivenessToDeadEnds () {
278
290
// TODO: OSSALifetimeCompletion: Once lifetimes are always complete, delete
279
291
// this method.
@@ -1356,8 +1368,8 @@ bool CanonicalizeOSSALifetime::computeLiveness() {
1356
1368
clear ();
1357
1369
return false ;
1358
1370
}
1371
+ extendLivenessToDeadEnds ();
1359
1372
if (respectsDeinitBarriers ()) {
1360
- extendLivenessToDeadEnds ();
1361
1373
extendLivenessToDeinitBarriers ();
1362
1374
}
1363
1375
if (accessBlockAnalysis) {
Original file line number Diff line number Diff line change @@ -28,8 +28,8 @@ func checkResult(_ plaintext: [UInt8]) {
28
28
29
29
@_semantics ( " optremark.sil-assembly-vision-remark-gen " )
30
30
public func run_ChaCha( _ N: Int ) {
31
- let key = Array ( repeating: UInt8 ( 1 ) , count: 32 ) // expected-remark {{release of type ' }}
32
- let nonce = Array ( repeating: UInt8 ( 2 ) , count: 12 ) // expected-remark {{release of type ' }}
31
+ let key = Array ( repeating: UInt8 ( 1 ) , count: 32 ) // expected-note {{of 'key }}
32
+ let nonce = Array ( repeating: UInt8 ( 2 ) , count: 12 ) // expected-note {{of 'nonce }}
33
33
34
34
var checkedtext = Array ( repeating: UInt8 ( 0 ) , count: 1024 ) // expected-note {{of 'checkedtext}}
35
35
ChaCha20 . encrypt ( bytes: & checkedtext, key: key, nonce: nonce)
@@ -44,3 +44,5 @@ public func run_ChaCha(_ N: Int) {
44
44
}
45
45
} // expected-remark {{release of type '}}
46
46
// expected-remark @-1 {{release of type '}}
47
+ // expected-remark @-2 {{release of type '}}
48
+ // expected-remark @-3 {{release of type '}}
Original file line number Diff line number Diff line change @@ -885,6 +885,33 @@ die:
885
885
unreachable
886
886
}
887
887
888
+ // CHECK-LABEL: begin running test {{.*}} on consume_copy_before_use_in_dead_end_2
889
+ // CHECK-LABEL: sil [ossa] @consume_copy_before_use_in_dead_end_2 : {{.*}} {
890
+ // CHECK-NOT: destroy_value [dead_end]
891
+ // CHECK-LABEL: } // end sil function 'consume_copy_before_use_in_dead_end_2'
892
+ // CHECK-LABEL: end running test {{.*}} on consume_copy_before_use_in_dead_end_2
893
+ sil [ossa] @consume_copy_before_use_in_dead_end_2 : $@convention(thin) (@owned C) -> () {
894
+ entry(%c : @owned $C):
895
+ cond_br undef, exit, die
896
+
897
+ exit:
898
+ destroy_value %c
899
+ %retval = tuple ()
900
+ return %retval
901
+
902
+ die:
903
+ %move = move_value %c
904
+ %copy = copy_value %move
905
+ specify_test "canonicalize_ossa_lifetime true false true %move"
906
+ apply undef(%move) : $@convention(thin) (@owned C) -> ()
907
+ %addr = alloc_stack $C
908
+ %token = store_borrow %copy to %addr
909
+ apply undef() : $@convention(thin) () -> ()
910
+ %reload = load_borrow %token
911
+ apply undef(%reload) : $@convention(thin) (@guaranteed C) -> ()
912
+ unreachable
913
+ }
914
+
888
915
// The destroy of a value must not be hoisted over a destroy of a copy of a
889
916
// partial_apply [on_stack] which captures the value.
890
917
// CHECK-LABEL: begin running test {{.*}} on destroy_after_pa_copy_destroy
You can’t perform that action at this time.
0 commit comments