-
Notifications
You must be signed in to change notification settings - Fork 10.7k
Closed
Labels
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.standard libraryArea: Standard library umbrellaArea: Standard library umbrella
Description
| Previous ID | SR-7948 |
| Radar | None |
| Original Reporter | @ole |
| Type | Bug |
Environment
Xcode 10 beta 1
Swift version 4.2 (swiftlang-1000.0.16.4 clang-1000.0.25.3)
macOS 10.13.4 (64 Bit)
Additional Detail from JIRA
| Votes | 1 |
| Component/s | Standard Library |
| Labels | Bug |
| Assignee | @moiseev |
| Priority | Medium |
md5: ee0a4e5e5dca13901478b4828f3f5e91
Issue Description:
The expressions (Int.min..<Int.max).count and (Int.min...Int.max).count correctly trap because of an integer overflow. However, the same expressions with UInt, Int64, and UInt64 don't trap. The half-open range versions each return -1, whereas the closed-range versions return 0.
Half-open ranges:
1> (UInt.min..<UInt.max).count
$R0: Int = -1
2> (Int64.min..<Int64.max).count
$R1: Int = -1
3> (UInt64.min..<UInt64.max).count
$R2: Int = -1
4> (Int.min..<Int.max).count
Execution interrupted. Enter code to recover and continue.
Enter LLDB commands to investigate (type :help for assistance.)
Process 45232 stopped
* thread #​1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)
frame #​0: 0x000000010116a752 libswiftCore.dylib`protocol witness for Swift.Strideable.distance(to: A) -> A.Stride in conformance Swift.Int : Swift.Strideable in Swift + 18
libswiftCore.dylib`protocol witness for Swift.Strideable.distance(to: A) -> A.Stride in conformance Swift.Int : Swift.Strideable in Swift:
-> 0x10116a752 <+18>: ud2
0x10116a754 <+20>: ud2
0x10116a756 <+22>: nopw %cs:(%rax,%rax)
libswiftCore.dylib`protocol witness for Swift.Strideable.advanced(by: A.Stride) -> A in conformance Swift.Int : Swift.Strideable in Swift:
0x10116a760 <+0>: pushq %rbp
Target 0: (repl_swift) stopped.Closed ranges:
1> (UInt.min...UInt.max).count
$R0: Int = 0
2> (Int64.min...Int64.max).count
$R1: Int = 0
3> (UInt64.min...UInt64.max).count
$R2: Int = 0
4> (Int.min...Int.max).count
Execution interrupted. Enter code to recover and continue.I think all of these should trap.
This is not a regression from Swift 4.1. I'm seeing the same behavior with Xcode 9.4 (Swift version 4.1.2 (swiftlang-902.0.54 clang-902.0.39.2)).
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.standard libraryArea: Standard library umbrellaArea: Standard library umbrella