[SR-8950] Runtime crash accessing memory on 32-bit device after initialising an enum with a large associated struct #51455
Labels
access control
Feature → modifiers: Access control and access levels
bug
A deviation from expected or documented behavior. Also: expected but undesirable behavior.
compiler
The Swift compiler in itself
regression
swift 4.2
Attachment: Download
Additional Detail from JIRA
md5: 95494830e0b32e6a93d1247237241cfe
Issue Description:
Updating to Swift 4.2/Xcode 10 seems to have surfaced a strange memory corruption ( ? ) issue when initialising an extremely large struct inside of an enum using associated types on a 32-bit device.
After a good few hours, I managed to narrow it down to the following sample code:
Using Xcode 10 (10A255) and it's packaged Swift 4.2 compiler, I ran the code on an iPhone 5c (iOS 10.3.3) where I am met with EXC_BAD_ACCESS. I can only seem to reproduce this issue using a 32-bit device. I've attached a sample project as well that you can run yourself.
There is a limit to my knowledge and I'm struggling to understand the actual cause of this issue but below are some points of interest:
The crash will only occur if the size of TestStruct is over ~2060 bytes.
The crash will only occur if TestStruct contains a Swift String and Date object.
The crash will only occur if the TestEnum has an additional case.
The crash does not occur in the iOS simulator, when run on macOS, or when run on a 64-bit device (both iOS 10 and iOS 11).
In this particular example, it only crashes when running in Debug mode (no compiler optimisations). This is not the case however in our main project but I am assuming that this is related to the fact that the compiler optimised most of the code away in this simple version.
The only workarounds that I've come across are to eliminate one of the above points for the code to execute correctly. Would be great if anybody is able to help me understand things further!
The text was updated successfully, but these errors were encountered: