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
22
3+ import Swift
34import Builtin
45
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) () -> ()
1011
1112// We used to crash on this IR. We would delete "%4" while there is still a
1213// (dead) user "%7" around.
@@ -15,15 +16,17 @@ struct Int64 {
1516// CHECK: %[[E:.+]] = function_ref @exit
1617// CHECK: apply %[[E]]
1718// CHECK: unreachable
18-
19+ // CHECK: } // end sil function 'unreachable_outside_block_user'
1920sil private @unreachable_outside_block_user : $@convention(thin) () -> Int64 {
2021bb0:
2122 %0 = integer_literal $Builtin.Int1, -1
2223 %1 = integer_literal $Builtin.Int32, 3
2324 // function_ref exit
2425 %2 = function_ref @exit : $@convention(thin) (Builtin.Int32) -> Never
2526 %3 = apply %2(%1) : $@convention(thin) (Builtin.Int32) -> Never
27+ // expected-note @-1 {{a call to a never-returning function}}
2628 %4 = integer_literal $Builtin.Int64, 7
29+ // expected-warning @-1 {{will never be executed}}
2730 cond_br %0, bb1, bb2
2831
2932bb1:
@@ -42,4 +45,35 @@ bb3 (%11: $Int64):
4245 return %11 : $Int64
4346}
4447
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