1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
|
// RUN: %target-sil-opt -enable-sil-verify-all %s -onone-simplification -simplify-instruction=init_enum_data_addr | %FileCheck %s
// REQUIRES: swift_in_compiler
import Swift
import Builtin
enum E {
case A(Int)
case B(AnyObject)
}
// CHECK-LABEL: sil @optional_int
// CHECK: %2 = enum $Optional<Int>, #Optional.some!enumelt, %1 : $Int
// CHECK: store %2 to %0 : $*Optional<Int>
// CHECK: %4 = tuple ()
// CHECK: return %4
// CHECK: } // end sil function 'optional_int'
sil @optional_int : $@convention(thin) (Int) -> @out Optional<Int> {
bb0(%0 : $*Optional<Int>, %1 : $Int):
%2 = init_enum_data_addr %0 : $*Optional<Int>, #Optional.some!enumelt
store %1 to %2 : $*Int
inject_enum_addr %0 : $*Optional<Int>, #Optional.some!enumelt
%5 = tuple ()
return %5 : $()
}
// CHECK-LABEL: sil [ossa] @ossa_trivial
// CHECK: %2 = enum $Optional<Int>, #Optional.some!enumelt, %1 : $Int
// CHECK: store %2 to [trivial] %0 : $*Optional<Int>
// CHECK: %4 = tuple ()
// CHECK: return %4
// CHECK: } // end sil function 'ossa_trivial'
sil [ossa] @ossa_trivial : $@convention(thin) (Int) -> @out Optional<Int> {
bb0(%0 : $*Optional<Int>, %1 : $Int):
%2 = init_enum_data_addr %0 : $*Optional<Int>, #Optional.some!enumelt
store %1 to [trivial] %2 : $*Int
inject_enum_addr %0 : $*Optional<Int>, #Optional.some!enumelt
%5 = tuple ()
return %5 : $()
}
// CHECK-LABEL: sil [ossa] @ossa_nontrivial
// CHECK: %2 = enum $E, #E.A!enumelt, %1 : $Int
// CHECK: store %2 to [init] %0 : $*E
// CHECK: %4 = tuple ()
// CHECK: return %4
// CHECK: } // end sil function 'ossa_nontrivial'
sil [ossa] @ossa_nontrivial : $@convention(thin) (Int) -> @out E {
bb0(%0 : $*E, %1 : $Int):
%2 = init_enum_data_addr %0 : $*E, #E.A!enumelt
store %1 to [trivial] %2 : $*Int
inject_enum_addr %0 : $*E, #E.A!enumelt
%5 = tuple ()
return %5 : $()
}
enum GenE<T> {
case A(Int)
case B(T)
}
// CHECK-LABEL: sil [ossa] @not_loadable
// CHECK: %2 = init_enum_data_addr
// CHECK: store %1 to [trivial] %2
// CHECK: inject_enum_addr
// CHECK: } // end sil function 'not_loadable'
sil [ossa] @not_loadable : $@convention(thin) <T> (Int) -> @out GenE<T> {
bb0(%0 : $*GenE<T>, %1 : $Int):
%2 = init_enum_data_addr %0 : $*GenE<T>, #GenE.A!enumelt
store %1 to [trivial] %2 : $*Int
inject_enum_addr %0 : $*GenE<T>, #GenE.A!enumelt
%5 = tuple ()
return %5 : $()
}
enum F {
case A(UnsafeMutableRawPointer)
case B(AnyObject)
}
// CHECK-LABEL: sil [ossa] @enum_data_addr
// CHECK: %2 = struct $UnsafeMutableRawPointer (%1 : $Builtin.RawPointer)
// CHECK: %3 = enum $F, #F.A!enumelt, %2 : $UnsafeMutableRawPointer
// CHECK: store %3 to [init] %0 : $*F
// CHECK: %5 = tuple ()
// CHECK: return %5
// CHECK: } // end sil function 'enum_data_addr'
sil [ossa] @enum_data_addr : $@convention(thin) (Builtin.RawPointer) -> @out F {
bb0(%0 : $*F, %1 : $Builtin.RawPointer):
%2 = init_enum_data_addr %0 : $*F, #F.A!enumelt
%3 = struct $UnsafeMutableRawPointer (%1 : $Builtin.RawPointer)
store %3 to [trivial] %2 : $*UnsafeMutableRawPointer
inject_enum_addr %0 : $*F, #F.A!enumelt
%6 = tuple ()
return %6 : $()
}
|