File tree Expand file tree Collapse file tree 2 files changed +56
-0
lines changed
lib/SILOptimizer/SemanticARC Expand file tree Collapse file tree 2 files changed +56
-0
lines changed Original file line number Diff line number Diff line change 27
27
#include " swift/SIL/MemAccessUtils.h"
28
28
#include " swift/SIL/OwnershipUtils.h"
29
29
#include " swift/SIL/Projection.h"
30
+ #include " swift/SIL/Test.h"
30
31
31
32
using namespace swift ;
32
33
using namespace swift ::semanticarc;
@@ -828,6 +829,20 @@ bool SemanticARCOptVisitor::tryPerformOwnedCopyValueOptimization(
828
829
return true ;
829
830
}
830
831
832
+ namespace swift ::test {
833
+ static FunctionTest SemanticARCOptsCopyValueOptsGuaranteedValueOptTest (
834
+ " semantic_arc_opts__copy_value_opts__guaranteed_value_opt" ,
835
+ [](auto &function, auto &arguments, auto &test) {
836
+ SemanticARCOptVisitor visitor (function, test.getPassManager (),
837
+ *test.getDeadEndBlocks (),
838
+ /* onlyMandatoryOpts=*/ false );
839
+
840
+ visitor.performGuaranteedCopyValueOptimization (
841
+ cast<CopyValueInst>(arguments.takeInstruction ()));
842
+ function.print (llvm::errs ());
843
+ });
844
+ } // end namespace swift::test
845
+
831
846
// ===----------------------------------------------------------------------===//
832
847
// Top Level Entrypoint
833
848
// ===----------------------------------------------------------------------===//
Original file line number Diff line number Diff line change
1
+ // RUN: not --crash %target-sil-opt -test-runner %s -o /dev/null 2>&1 | %FileCheck %s
2
+
3
+ sil_stage canonical
4
+
5
+ import Builtin
6
+ import Swift
7
+
8
+ struct Inner {
9
+ var o: Builtin.NativeObject
10
+ }
11
+ struct Outer {
12
+ var inner: Inner
13
+ }
14
+
15
+ // CHECK-LABEL: sil [ossa] @check_keep_copy_required_to_destroy_at_unreachable : {{.*}} {
16
+ // CHECK: copy_value
17
+ // CHECK-LABEL: } // end sil function 'check_keep_copy_required_to_destroy_at_unreachable'
18
+ sil [ossa] @check_keep_copy_required_to_destroy_at_unreachable : $@convention(thin) (@in_guaranteed Outer) -> () {
19
+ entry(%o_addr : $*Outer):
20
+ %o_copy = load [copy] %o_addr : $*Outer
21
+ %o_borrow = begin_borrow %o_copy : $Outer
22
+ %i = struct_extract %o_borrow : $Outer, #Outer.inner
23
+ %i_copy = copy_value %i : $Inner
24
+ specify_test "semantic_arc_opts__copy_value_opts__guaranteed_value_opt %i_copy"
25
+ (%o2_addr, %token) = begin_apply undef(%i_copy) : $@yield_once @convention(thin) (@guaranteed Inner) -> @yields @inout Outer
26
+ try_apply undef(%o2_addr) : $@convention(thin) (@inout Outer) -> @error any Error, normal success, error failure
27
+
28
+ success(%empty : $()):
29
+ end_apply %token as $()
30
+ destroy_value %i_copy : $Inner
31
+ end_borrow %o_borrow : $Outer
32
+ destroy_value %o_copy : $Outer
33
+ return undef : $()
34
+
35
+ failure(%error : @owned $any Error):
36
+ end_borrow %o_borrow : $Outer
37
+ destroy_value %error : $any Error
38
+ end_apply %token as $()
39
+ destroy_value [dead_end] %o_copy : $Outer
40
+ unreachable
41
+ }
You can’t perform that action at this time.
0 commit comments