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-13038] unknownObjectRetain crash with -Osize Swift optimization #55484
Comments
Comment by Sung Min Kim (JIRA) Afternoon! Any updates on this issue? bullock (JIRA User) Were you able to find a simple workaround for this? We're solving the issue assigning the text to a variable and then setting the .text from that variable, but this implies changes in the whole project and it's causing crashes on our release branch. |
Comment by Lance (JIRA) sungkim23 (JIRA User) We changed the computed var to a function and therefore have to change the call at the call site. |
Comment by Artsiom Karseka (JIRA) Guys, do you have any update here? Looks like we have a similar top-rate crash when setting text in UILabel from computed var with interpolated string. Do you have a robust workaround? Thank you. |
Comment by Sung Min Kim (JIRA) AKarseka (JIRA User) I find it weird no-one from Apple or Swift contributors have noticed this, but we gotta try to get someone to notice this bug, so far, the only way is what bullock (JIRA User) mentioned, either get the value from a func or you can set the computed var to a local variable and then use that variable. Neither solutions are robust per se, but it's the only way we're able to still ship our app... if we didn't find the workaround we'd have millions of users crashing every day. |
@swift-ci create |
Thanks for the report and the nice reproducer. I was able to replicate the crash here with Xcode 11.4, and verify that the code generated at the crash site is over-releasing the string. I was not able to replicate it with an Xcode 12 beta, and the code generated with that version looks good. Have you tried this with an Xcode 12 beta? If not, could you try it there and see if it also works for you? |
Comment by Cezary Wojcik (JIRA) Glad you're able to reproduce @mikeash! Unfortunately, migrating my actual codebase to Xcode 12 is pretty non-trivial, but w/ this example alone, I'm seeing the same behavior of a crash in Xcode 11.5 and no crash w/ Xcode 12. Are there possible (comprehensive) workarounds in Xcode 11.4+? Otherwise, means my codebase is probably stuck on using Xcode 11.2.1 until the AppStore is accepting builds from Xcode 12. |
Since this seems to be a codegen problem in the compiler, it's a bit outside my wheelhouse, but I will ask the people who know about that sort of thing and they or I will report back. One thing I did notice is that the problem seems to be connected to directly accessing the singleton instance with |
Comment by Cezary Wojcik (JIRA) Awesome, thanks for looking into it! Yeah, that kind of workaround works for known instances, but the problem with a really large codebase is that it's hard to identify / fix all possible instances + prevent new ones from getting in. So without comprehensively being able to fix this with some kind of compile flag or similar, can't really risk it. |
Comment by Cezary Wojcik (JIRA) Hey @mikeash, were you able to get ahold of anyone who could help further? Thanks! |
We don't seem to have any good ideas for a workaround without applying fixes at specific locations in code. Is this problem narrow enough that you could search for |
Comment by Cezary Wojcik (JIRA) I think it's feasible to try to find the existing ones, but a little harder to prevent new ones from sneaking in. Sounds like waiting until Xcode 12 it is - thanks for checking! |
Glad to be of service, sorry it didn't bear sweeter fruit. |
Attachment: Download
Additional Detail from JIRA
md5: da2e65be581761f2269c21c9636bc329
Issue Description:
When a formatted or interpolated String is returned from a computed Swift property and assigned to Obj-C instance (e.g. UIKit class) and the Swift optimization level is -Osize, app will crash at runtime with unknownObjectRetain
The text was updated successfully, but these errors were encountered: