Memory corruption due to Swift concurrency when deploying on iOS 15 and below

When we tried to migrate to Xcode 14 we bumped into serious problems with memory corruption. After thorough investigation, we found out that concurrency lib when back-deployed (to iOS 15 and below) corrupts heap.
We have opened an issue for that:

IMO it looks very serious. Can anybody from the Swift team tell if they are aware of this?
@Douglas_Gregor @John_McCall

I'm curious on what's going on here as well.

As a result, it's currently not feasible to target iOS versions lower than 16 and use Swift 5.7 with async functions and Tasks without encountering random crashes.

That's a scary claim.

We're currently developing a feature that requires Concurrency and is targeting iOS 15. One day, out the blue the application started crashing. The crash was reproducible and always at the same place. However that seemed totally random to me. I spent hours trying enabling some Core Data flags to gather a bit more data, but I ended up giving up on that. One day later, the rebuilt project just started working again. It almost smelled like some Xcode cache was cleaned up over night. (I didn't try to clean-build the project when I was facing the crashes.)

Unfortunately I cannot provide any reproducible code as the issue magically disappeared.

In the end we managed to reduce to a sample project.
There are some workarounds (-Osize instead of -Ospeed, for example), but they seem sub-optimal.

1 Like

We're tracking a fix to this problem now; hopefully we can get it done soon.