1
- // RUN: %target-sil-opt -module-name Swift - enable-sil-verify-all -noreturn-folding < %s | %FileCheck %s
1
+ // RUN: %target-sil-opt -enable-sil-verify-all -noreturn-folding -verify %s | %FileCheck %s
2
2
3
+ import Swift
3
4
import Builtin
4
5
5
- enum Never {}
6
-
7
- struct Int64 {
8
- var value: Builtin.Int64
9
- }
6
+ sil @exit : $@convention(thin) (Builtin.Int32) -> Never
7
+ sil @returnNever : $@convention(thin) () -> Never
8
+ sil @returnNeverThrows : $@convention(thin) () -> (Never, @error Error)
9
+ sil @returnNeverCoroutine : $@yield_once @convention(thin) () -> @yields Never
10
+ sil @doSomething : $@convention(thin) () -> ()
10
11
11
12
// We used to crash on this IR. We would delete "%4" while there is still a
12
13
// (dead) user "%7" around.
@@ -15,15 +16,17 @@ struct Int64 {
15
16
// CHECK: %[[E:.+]] = function_ref @exit
16
17
// CHECK: apply %[[E]]
17
18
// CHECK: unreachable
18
-
19
+ // CHECK: } // end sil function 'unreachable_outside_block_user'
19
20
sil private @unreachable_outside_block_user : $@convention(thin) () -> Int64 {
20
21
bb0:
21
22
%0 = integer_literal $Builtin.Int1, -1
22
23
%1 = integer_literal $Builtin.Int32, 3
23
24
// function_ref exit
24
25
%2 = function_ref @exit : $@convention(thin) (Builtin.Int32) -> Never
25
26
%3 = apply %2(%1) : $@convention(thin) (Builtin.Int32) -> Never
27
+ // expected-note @-1 {{a call to a never-returning function}}
26
28
%4 = integer_literal $Builtin.Int64, 7
29
+ // expected-warning @-1 {{will never be executed}}
27
30
cond_br %0, bb1, bb2
28
31
29
32
bb1:
@@ -42,4 +45,35 @@ bb3 (%11: $Int64):
42
45
return %11 : $Int64
43
46
}
44
47
45
- sil @exit : $@convention(thin) (Builtin.Int32) -> Never
48
+ // Make sure we do not emit any error here.
49
+ sil @ignore_use_apply : $@convention(thin) () -> () {
50
+ bb0:
51
+ %0 = function_ref @returnNever : $@convention(thin) () -> Never
52
+ %1 = apply %0() : $@convention(thin) () -> Never
53
+ ignored_use %1 : $Never
54
+ unreachable
55
+ }
56
+
57
+ // Make sure we do not emit any error here.
58
+ sil [ossa] @ignore_use_try_apply : $@convention(thin) () -> () {
59
+ bb0:
60
+ %0 = function_ref @returnNeverThrows : $@convention(thin) () -> (Never, @error Error)
61
+ try_apply %0() : $@convention(thin) () -> (Never, @error Error), normal bb1, error bb2
62
+
63
+ bb1(%2 : $Never):
64
+ ignored_use %2 : $Never
65
+ unreachable
66
+
67
+ bb2(%5 : @owned $Error):
68
+ %6 = builtin "unexpectedError"(%5 : $Error) : $()
69
+ unreachable
70
+ }
71
+
72
+ sil [ossa] @ignore_use_begin_apply : $@convention(thin) () -> () {
73
+ bb0:
74
+ %0 = function_ref @returnNeverCoroutine : $@yield_once @convention(thin) () -> @yields Never
75
+ (%1, %2) = begin_apply %0() : $@yield_once @convention(thin) () -> @yields Never
76
+ ignored_use %1
77
+ end_apply %2 as $()
78
+ unreachable
79
+ }
0 commit comments