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-10756] Encodable crash when using -Os optimization is used #53146

Open
swift-ci opened this issue May 23, 2019 · 12 comments
Open

[SR-10756] Encodable crash when using -Os optimization is used #53146

swift-ci opened this issue May 23, 2019 · 12 comments

Comments

@swift-ci
Copy link
Collaborator

@swift-ci swift-ci commented May 23, 2019

Previous ID SR-10756
Radar None
Original Reporter srna (JIRA User)
Type Bug

Attachment: Download

Environment

Swift 5, Optimization -Os, Release

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, Miscompile, OptimizedOnly, Optimizer, RunTimeCrash
Assignee None
Priority Medium

md5: 54efaf35d105951c4395268b6a8c7b8c

Issue Description:

We have a rather complex structure that is Encodable (compiler-generated, automatic).

When we use -Os optimization, the app crashes deterministically. When we turn off optimization, or use -O1, the problem disappears.

No change in code, just the optimization.

@belkadan
Copy link
Contributor

@belkadan belkadan commented May 23, 2019

By -O1 I'm assuming you mean just -O? ("Optimize for Speed" in Xcode). Or -Onone?

@belkadan
Copy link
Contributor

@belkadan belkadan commented May 23, 2019

Is this a project you can share? This probably isn't enough information to track down the issue.

@swift-ci
Copy link
Collaborator Author

@swift-ci swift-ci commented May 28, 2019

Comment by Tomas Srna (JIRA)

@belkadan The functioning optimization is "Fast [-O, O1]". As for the code, I'll try to isolate the problem and upload a mini project this week.

@belkadan
Copy link
Contributor

@belkadan belkadan commented May 28, 2019

That's not a Swift optimization setting; changing it does not affect how the Swift code in your target is built.

@swift-ci
Copy link
Collaborator Author

@swift-ci swift-ci commented May 29, 2019

Comment by Tomas Srna (JIRA)

@belkadan for Swift Compiler - Code Generation it is -Onone that works and -O that doesn't

@swift-ci
Copy link
Collaborator Author

@swift-ci swift-ci commented May 29, 2019

Comment by Tomas Srna (JIRA)

I tried to isolate the problem, but couldn't reproduce outside our project, which is not public, under heavy NDA. I'll try and send the crashlog, maybe it could help. 2019-05-22_08-26-28.8305_+0200-ec3f7a17da0884e8a195cc8c543c67da8b004207.crash

@belkadan
Copy link
Contributor

@belkadan belkadan commented May 29, 2019

Thanks. @eeckstein, shajrawi (JIRA User), does this sound familiar?

@eeckstein
Copy link
Member

@eeckstein eeckstein commented May 29, 2019

That's really hard to say without the project.
srna (JIRA User) If you cannot isolate the problem, there is another possibility to track this down: You can find the offending optimization by bisecting.
When you compile with -Osize, you can add the compiler option
-Xllvm -sil-opt-pass-count=<n>
where n the number of optimizations executed, e.g. 0 means all optimizations turned off.
If you can find the n where the crash occurs and does not occur with n-1, this would be very useful for us (I'll give you more instructions then).

@swift-ci
Copy link
Collaborator Author

@swift-ci swift-ci commented May 30, 2019

Comment by Tomas Srna (JIRA)

I tried it and the result is rather weird.

`-Xllvm -sil-opt-pass-count=1` — works
`-Xllvm -sil-opt-pass-count=2` — works
`-Xllvm -sil-opt-pass-count=3` — works
`-Xllvm -sil-opt-pass-count=4` — works
`-Xllvm -sil-opt-pass-count=8` — works
`-Xllvm -sil-opt-pass-count=16` — works
`-Xllvm -sil-opt-pass-count=128` — works
`-Xllvm -sil-opt-pass-count=1024` — works
without this flag — crashes

@eeckstein Can you give me a hint of how large <n> should I try?

@eeckstein
Copy link
Member

@eeckstein eeckstein commented May 30, 2019

n can be quite large (> 100000)
I took the opportunity and documented the whole procedure here: https://github.com/apple/swift/blob/master/docs/DebuggingTheCompiler.rst#identifying-an-optimizer-bug

Could you do that exercise and provide the name of the bad optimization and the SIL before and after the optimization?
(If you don't want to attach the SIL to the public Jira, you can also file a radar and attach it there).

@swift-ci
Copy link
Collaborator Author

@swift-ci swift-ci commented Jun 5, 2019

Comment by Tomas Srna (JIRA)

@eeckstein Thank you. To keep you posted, I am slowly approaching the N, currently the spread is +/- 50. The number is really big, at approximately 5 mil.

@swift-ci
Copy link
Collaborator Author

@swift-ci swift-ci commented Jun 6, 2019

Comment by Tomas Srna (JIRA)

So the crashing N=4916513, N-1 doesn't crash. I'll do the second step in near future.

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

No branches or pull requests

3 participants