Compiler crashes if conditions of the case clause are duplicated
| Originator: | kishikawakatsumi | ||
| Number: | rdar://21676778 | Date Originated: | 06-Jul-2015 00:15 AM |
| Status: | Open | Resolved: | |
| Product: | Developer Tools | Product Version: | |
| Classification: | Reproducible: | Always |
Summary:
Compiler crashes if conditions of the case clause are duplicated in the initializer.
For example: Conforming to RawRepresentable protocol
Steps to Reproduce:
1. Define following enum
2. Set build configuration in scheme to 'Release'
3. Build it
public enum Enum {
case A
case B
case C
}
extension Enum : RawRepresentable {
public init?(rawValue: Int) {
switch rawValue {
case 0:
self = A
case 1:
self = B
case 1:
self = B
default:
self = C
}
}
public var rawValue: Int {
switch self {
case A:
return 0
case B:
return 1
default:
return 2
}
}
}
Expected Results:
Build succeeded
Actual Results:
Build failed due to following error:
Command failed due to signal: Illegal instruction: 4
SIL verification failed: select_value dispatches on same case value more than once: !seenCaseValues.count(elt)
Verifying instruction:
%4 = load %3 : $*Builtin.Int64 // user: %10
%5 = integer_literal $Builtin.Int64, 0 // user: %10
%6 = enum $Enum, #Enum.A!enumelt // user: %10
%7 = integer_literal $Builtin.Int64, 1 // users: %10, %10
%7 = integer_literal $Builtin.Int64, 1 // users: %10, %10
%8 = enum $Enum, #Enum.B!enumelt // users: %10, %10
%8 = enum $Enum, #Enum.B!enumelt // users: %10, %10
%9 = enum $Enum, #Enum.C!enumelt // user: %10
-> %10 = select_value %4 : $Builtin.Int64, case %5: %6, case %7: %8, case %7: %8, default %9 : $Enum // user: %11
%11 = enum $Optional<Enum>, #Optional.Some!enumelt.1, %10 : $Enum // user: %12
In function:
// protocol witness for Swift.RawRepresentable.init <A where A: Swift.RawRepresentable> (A.Type)(rawValue : A.RawValue) -> Swift.Optional<A> in conformance EnumTest.Enum : Swift.RawRepresentable in EnumTest
sil [transparent] [thunk] @_TTWO8EnumTest4EnumSs16RawRepresentableS_FS1_CuRq_S1__fMq_FT8rawValueqq_S1_8RawValue_GSqq__ : $@convention(witness_method) (@out Optional<Enum>, @in Int, @thick Enum.Type) -> () {
bb0(%0 : $*Optional<Enum>, %1 : $*Int, %2 : $@thick Enum.Type):
%3 = struct_element_addr %1 : $*Int, #Int.value // user: %4
%4 = load %3 : $*Builtin.Int64 // user: %10
%5 = integer_literal $Builtin.Int64, 0 // user: %10
%6 = enum $Enum, #Enum.A!enumelt // user: %10
%7 = integer_literal $Builtin.Int64, 1 // users: %10, %10
%8 = enum $Enum, #Enum.B!enumelt // users: %10, %10
%9 = enum $Enum, #Enum.C!enumelt // user: %10
%10 = select_value %4 : $Builtin.Int64, case %5: %6, case %7: %8, case %7: %8, default %9 : $Enum // user: %11
%11 = enum $Optional<Enum>, #Optional.Some!enumelt.1, %10 : $Enum // user: %12
store %11 to %0 : $*Optional<Enum> // id: %12
%13 = tuple () // user: %14
return %13 : $() // id: %14
}
Version:
OS X 10.10.3 (14D136), Version 7.0 beta (7A121l)
OS X 10.11 (15A204h), Version 7.0 beta (7A120f)
Notes:
This crash is occurred RELEASE build only
Configuration:
MacBookPro10,1, 16GB RAM
MacBook8,1, 8GB RAM
Attachments:
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!