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-3295] LLVM Crash using AutoreleasingUnsafeMutablePointer<Bool?>? #45883

Open
swift-ci opened this issue Nov 30, 2016 · 2 comments
Open

[SR-3295] LLVM Crash using AutoreleasingUnsafeMutablePointer<Bool?>? #45883

swift-ci opened this issue Nov 30, 2016 · 2 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-3295
Radar None
Original Reporter cocoanetics (JIRA User)
Type Bug
Status Reopened
Resolution

Attachment: Download

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug
Assignee None
Priority Medium

md5: 2e9c072577a6f5a8f365245e604f5601

Issue Description:

The following code crashes LLVM, paste that into a Playground:

import Foundation

extension Scanner
{
    func scanBool(_ result: AutoreleasingUnsafeMutablePointer<Bool?>?) -> Bool
    {
        result?.pointee = true
        return true
    }
}

let scanner = Scanner(string: "foo")
var b: Bool?
scanner.scanBool(&b)

You get "LLDB RPC server has crashed." I've attached a crash report.

Workaround: If I change the thing to an NSNumber? it works. Also changing the parameter to an inout works too, although then you lose the ability to specify nil as receiving variable.

The same crash occurs when passing a swift struct. So apparently there is a problem converting certain swift types into AutoreleasingUnsafeMutablePointers.

@belkadan
Copy link
Contributor

belkadan commented Dec 9, 2016

You're not supposed to use AutoreleasingUnsafeMutablePointer with a type that isn't a class or Objective-C block. What would it mean to autorelease a Bool?

(This ought to be a constraint on AutoreleasingUnsafeMutablePointer; unfortunately we don't have the language features to recognize the set of types that are okay. But you should prefer UnsafeMutablePointer in Swift anyway.)

@belkadan
Copy link
Contributor

belkadan commented Dec 9, 2016

I'll leave this open for QoI; it might be worth just hardcoding the allowed cases in the compiler even though it can't be expressed in the library.

@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
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself
Projects
None yet
Development

No branches or pull requests

2 participants