mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Type annotations for instruction operands are omitted, e.g. ``` %3 = struct $S(%1, %2) ``` Operand types are redundant anyway and were only used for sanity checking in the SIL parser. But: operand types _are_ printed if the definition of the operand value was not printed yet. This happens: * if the block with the definition appears after the block where the operand's instruction is located * if a block or instruction is printed in isolation, e.g. in a debugger The old behavior can be restored with `-Xllvm -sil-print-types`. This option is added to many existing test files which check for operand types in their check-lines.
113 lines
3.5 KiB
Plaintext
113 lines
3.5 KiB
Plaintext
// RUN: %target-sil-opt -sil-print-types -enable-experimental-feature MoveOnlyEnumDeinits -enable-sil-verify-all -sil-combine %s | %FileCheck %s
|
|
|
|
// REQUIRES: swift_feature_MoveOnlyEnumDeinits
|
|
|
|
sil_stage canonical
|
|
|
|
import Builtin
|
|
import Swift
|
|
|
|
struct S : ~Copyable {
|
|
deinit {}
|
|
}
|
|
|
|
struct FileDescriptor: ~Copyable {
|
|
var fd: Builtin.Int64
|
|
|
|
init(fd: Builtin.Int64)
|
|
deinit
|
|
}
|
|
|
|
enum MaybeFileDescriptor: ~Copyable {
|
|
case some(FileDescriptor)
|
|
case nothing
|
|
|
|
consuming func discard() { discard self }
|
|
|
|
deinit
|
|
}
|
|
|
|
struct Wrapper<T>: ~Copyable {
|
|
var t: T
|
|
}
|
|
|
|
sil @getWrappedValue : $@convention(thin) <T> (@in_guaranteed Wrapper<T>) -> @out T
|
|
|
|
// Test that a release_value is not removed for a struct-with-deinit.
|
|
// Doing so would forget the deinit.
|
|
//
|
|
// public func testStructDeinit() {
|
|
// var s = S()
|
|
// }
|
|
//
|
|
// CHECK-LABEL: sil @testStructDeinit : $@convention(thin) () -> () {
|
|
// CHECK: release_value %{{.*}} : $S
|
|
// CHECK-LABEL: } // end sil function 'testStructDeinit'
|
|
sil @testStructDeinit : $@convention(thin) () -> () {
|
|
bb0:
|
|
%0 = struct $S ()
|
|
release_value %0 : $S
|
|
%5 = tuple ()
|
|
return %5 : $()
|
|
}
|
|
|
|
// Test that a release_value is not replaced for a enum-with-deinit.
|
|
// Doing so would forget the deinit.
|
|
//
|
|
// CHECK-LABEL: sil hidden [noinline] @testEnumDeinit : $@convention(thin) () -> () {
|
|
// CHECK: release_value %{{.*}} : $MaybeFileDescriptor
|
|
// CHECK-LABEL: } // end sil function 'testEnumDeinit'
|
|
sil hidden [noinline] @testEnumDeinit : $@convention(thin) () -> () {
|
|
bb0:
|
|
%0 = integer_literal $Builtin.Int64, 0
|
|
%26 = struct $FileDescriptor (%0 : $Builtin.Int64)
|
|
%38 = enum $MaybeFileDescriptor, #MaybeFileDescriptor.some!enumelt, %26 : $FileDescriptor
|
|
release_value %38 : $MaybeFileDescriptor
|
|
%42 = tuple ()
|
|
return %42 : $()
|
|
}
|
|
|
|
// Test that a release of a trivial payload is not removed.
|
|
//
|
|
// CHECK-LABEL: sil hidden [noinline] @testEnumDeinitTrivialPayload : $@convention(thin) () -> () {
|
|
// CHECK: release_value %{{.*}} : $MaybeFileDescriptor
|
|
// CHECK-LABEL: } // end sil function 'testEnumDeinitTrivialPayload'
|
|
sil hidden [noinline] @testEnumDeinitTrivialPayload : $@convention(thin) () -> () {
|
|
bb0:
|
|
%0 = enum $MaybeFileDescriptor, #MaybeFileDescriptor.nothing!enumelt // users: %2, %1
|
|
debug_value %0 : $MaybeFileDescriptor, var, name "maybe" // id: %1
|
|
release_value %0 : $MaybeFileDescriptor
|
|
%9 = tuple ()
|
|
return %9 : $()
|
|
}
|
|
|
|
// Test that a move into a discarded value does not result in a destroy_addr
|
|
//
|
|
// CHECK-LABEL: sil @testNoDeinit : $@convention(method) <T> (@in Wrapper<T>) -> @out T {
|
|
// CHECK-NOT: destroy_addr
|
|
// CHECK-LABEL: } // end sil function 'testNoDeinit'
|
|
sil @testNoDeinit : $@convention(method) <T> (@in Wrapper<T>) -> @out T {
|
|
bb0(%0 : $*T, %1 : $*Wrapper<T>):
|
|
%2 = function_ref @getWrappedValue : $@convention(thin) <T> (@in_guaranteed Wrapper<T>) -> @out T
|
|
%3 = apply %2<T>(%0, %1) : $@convention(thin) <τ_0_0> (@in_guaranteed Wrapper<τ_0_0>) -> @out τ_0_0
|
|
%4 = alloc_stack $Wrapper<T>
|
|
copy_addr [take] %1 to [init] %4 : $*Wrapper<T>
|
|
// discard
|
|
dealloc_stack %4 : $*Wrapper<T>
|
|
%9 = tuple ()
|
|
return %9 : $()
|
|
}
|
|
|
|
// CHECK-LABEL: sil hidden [ossa] @testSDeinit : $@convention(method) (@owned S) -> () {
|
|
// CHECK: bb0(%0 : @owned $S):
|
|
// CHECK: [[DD:%.*]] = drop_deinit %0 : $S
|
|
// CHECK: destroy_value [[DD]] : $S
|
|
// CHECK-LABEL: } // end sil function 'testSDeinit'
|
|
sil hidden [ossa] @testSDeinit : $@convention(method) (@owned S) -> () {
|
|
bb0(%0 : @owned $S):
|
|
%1 = drop_deinit %0 : $S
|
|
destroy_value %1 : $S
|
|
%64 = tuple ()
|
|
return %64 : $()
|
|
}
|