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

Comments

@an0
Copy link
Mannequin

@an0 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

@belkadan belkadan commented Jun 25, 2018

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

@jckarter
Copy link
Member

@jckarter jckarter commented Jun 25, 2018

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

@jckarter
Copy link
Member

@jckarter jckarter commented Jun 25, 2018

@swift-ci create

@belkadan
Copy link
Contributor

@belkadan belkadan commented Jun 25, 2018

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

@jckarter jckarter commented Jun 25, 2018

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

@jckarter jckarter commented Jun 25, 2018

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

@aschwaighofer aschwaighofer commented Jun 26, 2018

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

@aschwaighofer
Copy link
Member

@aschwaighofer aschwaighofer commented Jun 26, 2018

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
This issue was closed.
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