Files
swift-mirror/test/SIL/OwnershipVerifier/unreachable_code.sil
Erik Eckstein 18063707b5 Optimizer: enable complete OSSA lifetimes throughout the pass pipeline
This new OSSA invariant simplifies many optimizations because they don't have to take care of the corner case of incomplete lifetimes in dead-end blocks.

The implementation basically consists of these changes:
* add the lifetime completion utility
* add a flag in SILFunction which tells optimization that they need to run the lifetime completion utility
* let all optimizations complete lifetimes if necessary
* enable the ownership verifier to check complete lifetimes
2026-01-22 17:41:48 +01:00

158 lines
3.6 KiB
Plaintext

// RUN: %target-sil-opt -sil-ownership-verifier-enable-testing -ownership-verifier-textual-error-dumper -enable-sil-verify-all=0 -o /dev/null %s 2>&1 | %FileCheck %s
// REQUIRES: asserts
// Make sure that we properly handle unreachable code the likes of which come
// from SILGen. This file should never crash.
sil_stage raw
import Builtin
//////////////////
// Declarations //
//////////////////
enum Never {}
sil @no_return_function : $@convention(thin) () -> Never
sil @create_object : $@convention(thin) () -> @owned Builtin.NativeObject
sil @use_object : $@convention(thin) (@owned Builtin.NativeObject) -> ()
///////////
// Tests //
///////////
// CHECK-LABEL: Function: 'test1'
// CHECK: Owned function parameter without lifetime ending uses!
sil [ossa] @test1 : $@convention(thin) (@owned Builtin.NativeObject, @owned Builtin.NativeObject) -> () {
bb0(%0 : @owned $Builtin.NativeObject, %1 : @owned $Builtin.NativeObject):
destroy_value %1 : $Builtin.NativeObject
unreachable
}
// CHECK-LABEL: Function: 'test2'
// CHECK: Error! Found a leak due to a consuming post-dominance failure!
sil [ossa] @test2 : $@convention(thin) (@owned Builtin.NativeObject) -> () {
bb0(%0 : @owned $Builtin.NativeObject):
cond_br undef, bb1, bb2
bb1:
unreachable
bb2:
destroy_value %0 : $Builtin.NativeObject
%9999 = tuple()
return %9999 : $()
}
// CHECK-LABEL: Function: 'test3'
// CHECK: Error! Found a leak due to a consuming post-dominance failure!
sil [ossa] @test3 : $@convention(thin) (@owned Builtin.NativeObject) -> () {
bb0(%0 : @owned $Builtin.NativeObject):
br bb1(%0 : $Builtin.NativeObject)
bb1(%1 : @owned $Builtin.NativeObject):
cond_br undef, bb2, bb3
bb2:
unreachable
bb3:
br bb1(%1 : $Builtin.NativeObject)
}
// CHECK-LABEL: Function: 'test4'
// CHECK: Error! Found a leak due to a consuming post-dominance failure!
sil [ossa] @test4 : $@convention(thin) (@owned Builtin.NativeObject) -> () {
bb0(%0 : @owned $Builtin.NativeObject):
br bb1(%0 : $Builtin.NativeObject)
bb1(%1 : @owned $Builtin.NativeObject):
%2 = copy_value %1 : $Builtin.NativeObject
cond_br undef, bb2, bb3
bb2:
unreachable
bb3:
destroy_value %1 : $Builtin.NativeObject
cond_br undef, bb4, bb5
bb4:
br bb1(%2 : $Builtin.NativeObject)
bb5:
destroy_value %2 : $Builtin.NativeObject
%9999 = tuple()
return %9999 : $()
}
// CHECK-LABEL: Function: 'test5'
// CHECK: Error! Found a leak due to a consuming post-dominance failure!
sil [ossa] @test5 : $@convention(thin) (@owned Builtin.NativeObject) -> () {
bb0(%0 : @owned $Builtin.NativeObject):
cond_br undef, bb1, bb2
bb1:
cond_br undef, bb3, bb4
bb2:
br bb5
bb3:
unreachable
bb4:
br bb5
bb5:
destroy_value %0 : $Builtin.NativeObject
%9999 = tuple()
return %9999 : $()
}
// CHECK-NOT: Function: 'test6'
sil [ossa] @test6 : $@convention(thin) (@owned Builtin.NativeObject) -> () {
bb0(%0 : @owned $Builtin.NativeObject):
cond_br undef, bb1, bb2
bb1:
cond_br undef, bb3, bb4
bb2:
br bb5
bb3:
destroy_value %0 : $Builtin.NativeObject
unreachable
bb4:
br bb5
bb5:
destroy_value %0 : $Builtin.NativeObject
%9999 = tuple()
return %9999 : $()
}
// CHECK-LABEL: Function: 'test7'
// CHECK: Error! Found a leak due to a consuming post-dominance failure!
sil [ossa] @test7 : $@convention(thin) (@owned Builtin.NativeObject) -> () {
bb0(%0 : @owned $Builtin.NativeObject):
%1 = begin_borrow %0 : $Builtin.NativeObject
cond_br undef, bb1, bb2
bb1:
end_borrow %1 : $Builtin.NativeObject
destroy_value %0 : $Builtin.NativeObject
%9999 = tuple()
return %9999 : $()
bb2:
end_borrow %1 : $Builtin.NativeObject
br bb3
bb3:
unreachable
}