Skip to content

Regression: withTaskGroup crashes immediately for iOSAppOnMac #75771

Open
@KaiOelfke

Description

@KaiOelfke

Description

With Xcode 16.0 beta 5 and Swift 6.0 (6.0.0.7.6) the code sample below crashes, when running as iOS app on mac (iOS apps can run on macOS devices with Apple Silicon). E.g. this applies to destinations where https://developer.apple.com/documentation/foundation/processinfo/3608556-isiosapponmac ProcessInfo.processInfo.isiOSAppOnMac is true.

Reproduction

Create a new iOS SwiftUI project with the default template and extend the template ContentView with a task modifier and a task group or just use withTaskGroup anywhere else.

import SwiftUI

struct ContentView: View {
    var body: some View {
        VStack {
            Image(systemName: "globe")
                .imageScale(.large)
                .foregroundStyle(.tint)
            Text("Hello, world!")
        }
        .padding()
        .task {
            await withTaskGroup(of: Void.self) { _ in } // Thread 1: EXC_BAD_ACCESS (code=1, address=0x4)
        }
    }
}

Stack dump

Thread 1: EXC_BAD_ACCESS (code=1, address=0x4)

    0x102e3d1cc <+204>: str    x10, [x22]
    0x102e3d1d0 <+208>: adrp   x10, 0
    0x102e3d1d4 <+212>: add    x10, x10, #0x260          ; (1) await resume partial function for back deployment thunk for Swift.withTaskGroup<ChildTaskResult, GroupResult where ChildTaskResult: Swift.Sendable>(of: ChildTaskResult.Type, returning: GroupResult.Type, isolation: isolated Swift.Optional<Swift.Actor>, body: (inout Swift.TaskGroup<ChildTaskResult>) async -> GroupResult) async -> GroupResult at <compiler-generated>
    0x102e3d1d8 <+216>: str    x10, [x22, #0x8]
    0x102e3d1dc <+220>: str    x9, [x29, #0x10]
    0x102e3d1e0 <+224>: ldp    x29, x30, [sp, #0x70]
    0x102e3d1e4 <+228>: and    x29, x29, #0xefffffffffffffff
    0x102e3d1e8 <+232>: add    sp, sp, #0x80
    0x102e3d1ec <+236>: br     x8
    0x102e3d1f0 <+240>: adrp   x8, 7
    0x102e3d1f4 <+244>: ldr    x8, [x8, #0x288]
->  0x102e3d1f8 <+248>: ldr    w8, [x8, #0x4]
    0x102e3d1fc <+252>: mov    x0, x8
    0x102e3d200 <+256>: bl     0x102e40670               ; symbol stub for: swift_task_alloc
    0x102e3d204 <+260>: ldur   x10, [x29, #-0x20]
    0x102e3d208 <+264>: ldur   x9, [x29, #-0x18]
    0x102e3d20c <+268>: ldur   x8, [x29, #-0x28]
    0x102e3d210 <+272>: ldr    x1, [sp, #0x38]
    0x102e3d214 <+276>: ldr    x2, [sp, #0x30]
    0x102e3d218 <+280>: ldr    x3, [sp, #0x28]
    0x102e3d21c <+284>: ldr    x4, [sp, #0x20]

Expected behavior

withTaskGroup should not crash and behave as in previous Xcode / Swift versions.

Environment

Xcode 16.0 beta 5 (16A5221g)
Swift 6.0 (6.0.0.7.6)
iOSAppOnMac

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    TaskGroupArea → standard library → Concurrency: The `TaskGroup` typebugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfconcurrencyFeature: umbrella label for concurrency language featurescrashBug: A crash, i.e., an abnormal termination of software

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions