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-8090] UnsafeMutablePointer.withMemoryRebound(to:capacity:_:) crashes #50623

Closed
an0 mannequin opened this issue Jun 24, 2018 · 8 comments
Closed

[SR-8090] UnsafeMutablePointer.withMemoryRebound(to:capacity:_:) crashes #50623

an0 mannequin opened this issue Jun 24, 2018 · 8 comments
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself crash Bug: A crash, i.e., an abnormal termination of software regression run-time crash Bug → crash: Swift code crashed during execution swift 4.2

Comments

@an0
Copy link
Mannequin

an0 mannequin commented Jun 24, 2018

Previous ID SR-8090
Radar rdar://problem/41202926
Original Reporter @an0
Type Bug
Status Resolved
Resolution Done

Attachment: Download

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, 4.2Regression, RunTimeCrash
Assignee @aschwaighofer
Priority Medium

md5: c5cc09c9166c89fdf7c203ffdac97417

Issue Description:

In swift-DEVELOPMENT-SNAPSHOT-2018-06-22-a-osx, this code:

    var info = task_basic_info()
    var infoSize = mach_msg_type_number_t(MemoryLayout<task_basic_info>.size / MemoryLayout<natural_t>.size)
    withUnsafeMutablePointer(to: &info) { infoPointer in
      infoPointer.withMemoryRebound(to: integer_t.self, capacity: MemoryLayout<task_basic_info>.size / MemoryLayout<integer_t>.size) {
        let result = task_info(mach_task_self_, task_flavor_t(TASK_BASIC_INFO), $0, &infoSize)
        if result != KERN_SUCCESS {
          print("Failed to get task info: \(result)")
        }
      }
    }

causes this crash on devices(mine is iPhone 6s) but not on simulators:

#&#8203;0 0x00000001046f84e4 in thunk for @callee_guaranteed (@unowned UnsafeMutablePointer<Int32>) -> (@error @owned Error) ()
 #&#8203;1 0x00000001046f8800 in partial apply for thunk for @callee_guaranteed (@unowned UnsafeMutablePointer<Int32>) -> (@error @owned Error) ()
 #&#8203;2 0x0000000104c245f4 in UnsafePointer.withMemoryRebound<A, B>(to:capacity:_:) ()
 #&#8203;3 0x0000000104e307f8 in UnsafeMutablePointer.withMemoryRebound<A, B>(to:capacity:_:) ()
 #&#8203;4 0x00000001046f81d0 in closure #&#8203;1 in UIDevice.getTaskInfo() at /Users/an0/Desktop/WithMemoryReboundBug/WithMemoryReboundBug/UIDevice+Memory.swift:18
 #&#8203;5 0x00000001046f8254 in partial apply for closure #&#8203;1 in UIDevice.getTaskInfo() ()
 #&#8203;6 0x00000001046f8554 in thunk for @callee_guaranteed (@unowned UnsafeMutablePointer<task_basic_info>) -> (@error @owned Error) ()
 #&#8203;7 0x00000001046f85e4 in partial apply for thunk for @callee_guaranteed (@unowned UnsafeMutablePointer<task_basic_info>) -> (@error @owned Error) ()
 #&#8203;8 0x0000000104cc825c in withUnsafePointer<A, B>(to:_:) ()
 #&#8203;9 0x0000000104e32438 in withUnsafeMutablePointer<A, B>(to:_:) ()
@belkadan
Copy link
Contributor

aschwaighofer@apple.com (JIRA User), is this the thing you just fixed with withoutActuallyEscaping?

@jckarter
Copy link
Member

Would Arnold's fix impact code that doesn't use withoutActuallyEscaping?

@jckarter
Copy link
Member

@swift-ci create

@belkadan
Copy link
Contributor

IIUC it was a general problem with thunking of nested closures, but I wasn't following it too closely. You could be right.

@jckarter
Copy link
Member

I wasn't able to reproduce the crash with the attached project using the default toolchain in Xcode 10, maybe it's a recent regression.

@jckarter
Copy link
Member

Hm, I wasn't able to reproduce with the 4.2 snapshot toolchain from 2018-06-23 either. @an0 did you have any other unusual build settings on the attached project when it crashes for you?

@aschwaighofer
Copy link
Member

Reproduces on an arm64 device with a current 4.2 snapshot for me.

@aschwaighofer
Copy link
Member

This will be fixed as soon as the toolchains pick up apple/swift-llvm@9283149

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added the crash Bug: A crash, i.e., an abnormal termination of software label Dec 12, 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 crash Bug: A crash, i.e., an abnormal termination of software regression run-time crash Bug → crash: Swift code crashed during execution swift 4.2
Projects
None yet
Development

No branches or pull requests

4 participants