Decimal.init(value: UInt64) crashes for very large values

Originator:dr.eric.roller
Number:rdar://30857559 Date Originated:05/03/2017
Status:Open Resolved:
Product:iOS + SDK Product Version:Swift 3.0.2 on iOS 10.2.1
Classification:Foundation Reproducible:yes
 
For values near UInt64.max, Decimal.init() crashes. Two examples:

(lldb) po Decimal.init(UInt64.max - 1023)
error: warning: couldn't get required object pointer (substituting NULL): Couldn't load 'self' because its value couldn't be evaluated

error: Execution was interrupted, reason: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0).
The process has been returned to the state before expression evaluation.


(lldb) po Decimal.init(UInt64.max - 1024)
▿ 18446744073709547520
  ▿ _mantissa : 8 elements
    - .0 : 38912
    - .1 : 39321
    - .2 : 39321
    - .3 : 6553
    - .4 : 0
    - .5 : 0
    - .6 : 0
    - .7 : 0

Steps to Reproduce:
In lldb, type:

po Decimal.init(UInt64.max - 1023)

Expected Results:
▿ 18446744073709547521
  ▿ _mantissa : 8 elements
    - .0 : 38913
    - .1 : 39321
    - .2 : 39321
    - .3 : 6553
    - .4 : 0
    - .5 : 0
    - .6 : 0
    - .7 : 0

Actual Results:
------------- iPad Air 2 output: ------------
error: warning: couldn't get required object pointer (substituting NULL): Couldn't load 'self' because its value couldn't be evaluated

error: Execution was interrupted, reason: EXC_BREAKPOINT (code=1, subcode=0x100a007c8).
The process has been returned to the state before expression evaluation.

------------- Simulator output: ----------------
error: warning: couldn't get required object pointer (substituting NULL): Couldn't load 'self' because its value couldn't be evaluated

error: Execution was interrupted, reason: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0).
The process has been returned to the state before expression evaluation.

Notes:
Any legal UInt64 value should be supported, even UInt64.max.

Configuration:
Seen in lldb (debugging on an app on an iPad Air 2 running iOS 10.2.1, or Simulator iOS10). Similar problem seen in swift repl.

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!