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-102] Optimizer introduces EXC_BAD_ACCESS; fills String with garbage #42724

Closed
drewcrawford opened this issue Dec 7, 2015 · 14 comments
Closed
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself optimized only Flag: An issue whose reproduction requires optimized compilation

Comments

@drewcrawford
Copy link
Contributor

Previous ID SR-102
Radar rdar://23853221
Original Reporter @drewcrawford
Type Bug
Status Resolved
Resolution Done

Attachment: Download

Environment

Xcode Version 7.1.1 (7B1005)
OSX 10.11.1 (15B42)
The Swift that ships with Xcode

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, OptimizedOnly
Assignee @gottesmm
Priority Medium

md5: 9cad99f685ab340bc14e9b92518c1eff

Issue Description:

In the attached project, an optimizer pass seems to (incorrectly) optimize out a string. The result is that the string is both live and holds garbage data.

1. Open attached project
2. Set configuration to Release
3. Run

Expected results:

Hello, World! path /api/bots/test/integrations Data <74657374>

Functions as expected in Debug configuration.

Actual results:

Hello, World! path /api/bots/test/integrati\250\262,\262,, Segmentation Fault: 11

I have minimized this example as well as I can, and I think it's an optimizer bug (setting component to Compiler), but in practice reproducing it seems to require calling dataUsingEncoding for reasons I don't understand.

@drewcrawford
Copy link
Contributor Author

Still fresh in new config

Xcode Version 7.2 (7C68)
OSX 10.11.2 (15C50)
The Swift that ships with this Xcode

@jckarter
Copy link
Member

Michael, who'd be a good candidate to look into this?

@gottesmm
Copy link
Member

In general you should send these to Nadav. But it is fine to park them on me in the short term.

@gottesmm
Copy link
Member

To the reporter, we are going to be using the other bug tracker field to relate to our internal bug tracking system (I am not sure if in JIRA we can do multiple, but we should look into this).

So I need to relate this to our internal radar number. Here is the issue you posted: https://code.sealedabstract.com/drewcrawford/CaveJohnson2/issues/10.

@gottesmm
Copy link
Member

I am looking at this now.

@gottesmm
Copy link
Member

I have reproduced a crash with optimization given this compiler:

Apple Swift version 2.1.1 (swiftlang-700.1.101.13 clang-700.1.81)
Target: x86_64-apple-darwin15.0.0

I am trying with ToT.

@gottesmm
Copy link
Member

This is my single file test case.


import Foundation

public final class ServerConfig { }

public final class XCSAPI {
private static func buildRequest(path: String, method: String = "GET", serverConfig: ServerConfig) throws -> [String: AnyObject] {
print("path (path)")
let url = NSURL(string: "https://:20343(path)")!
print("Data ("test".dataUsingEncoding(NSUTF8StringEncoding)!)")
return [:]
}
public static func integrateNow(botID: String, serverConfig: ServerConfig) throws -> Int {
//print(botID)
let response = try buildRequest("/api/bots/(botID)/integrations", method: "POST", serverConfig: serverConfig)
return 0
}

}

print("Hello, World!")

try! XCSAPI.integrateNow("test", serverConfig: ServerConfig())


@gottesmm
Copy link
Member

I am reproducing with ToT btw. I am bisecting now.

@gottesmm
Copy link
Member

It looks like the pass that exposes the issue is ARCSequenceOpts. It may just be exposing other bad behavior though.

@gottesmm
Copy link
Member

Ok I figured out the problem. It is an issue with ARC but it is relatively benign in the sense that I already know the solution and it shouldn't be too bad. The issue is how we are handling the use of a try_apply insertion point. I thought due to a quirk in the way we compute insertion points this would not come up, but I was incorrect. So now I need to make the appropriate change to handle this correctly.

@gottesmm
Copy link
Member

Turns out a similar problem can occur with loops if our pre-header insertion fails. I fixed this in:

To git@github.com:apple/swift.git
61e2b30..b235064 master -> master

@gottesmm
Copy link
Member

I have a fix, I am just writing more tests/checking for any perf issues.

@gottesmm
Copy link
Member

I have everything waiting to go. I am just waiting for Dmitri to fix the perf test suite so I can measure before/after performance just in case.

@gottesmm
Copy link
Member

To git@github.com:apple/swift.git
86e6b81..4f69bfc master -> master

@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
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself optimized only Flag: An issue whose reproduction requires optimized compilation
Projects
None yet
Development

No branches or pull requests

3 participants