Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-2339] "Illegal instruction" crash on UInt64 conversions to UInt (armv7 32bit platform) #44946

swift-ci opened this issue Aug 14, 2016 · 3 comments


Copy link

@swift-ci swift-ci commented Aug 14, 2016

Previous ID SR-2339
Radar None
Original Reporter jmarcelino (JIRA User)
Type Bug
Status Resolved
Resolution Invalid

Swift version 3.0-dev (LLVM e6ce0a6282, Clang 4ca9e01a7c, Swift b906a25)
Target: armv7--linux-gnueabihf

Additional Detail from JIRA
Votes 0
Component/s Standard Library
Labels Bug, RunTimeCrash, arm
Assignee None
Priority Medium

md5: 2a13ba44941fd11781b937d55d57c98d

Issue Description:

Code that relies on conversion from UInt64 to UInt or UInt32 is crashing at run-time on 32bit ARM (armv7) with an error of Illegal instruction.

One example where such code is used is the Swift Package Manager.
The code below replicates the issue:

let u64sample: UInt64 = 0x1234567890ABCDEF
print ("UInt64: \(u64sample)")

var i = UInt(u64sample)
print ("UInt: \(i)")

In this case the UInt(u64sample) step causes the run-time crash

Copy link

@belkadan belkadan commented Aug 15, 2016

This is correct behavior. The converting (unlabeled) initializer for integers always traps if the value to convert is out of bounds. Use init(truncating:) if you want C-like behavior.

Copy link
Collaborator Author

@swift-ci swift-ci commented Aug 15, 2016

Comment by Jose (JIRA)

Thanks Jordan.
I understand that and it's a good idea to throw an error on an attempt at a conversion which leads to loss of data, but perhaps “Illegal instruction” isn’t a good description for it...

For example attempting to initialise the same UInt from a integer literal shows a much better error message

var p = UInt(0x1234567890ABCDEF)

error: integer literal '1311768467294899695' overflows when stored into 'Int'

Copy link

@belkadan belkadan commented Aug 15, 2016

Ah, yes, that's definitely true. This is SR-578.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet

No branches or pull requests

2 participants