Skip to content

Runtime crash when accessing the span of an empty InlineArray #85265

@Jnosh

Description

@Jnosh

Description

An empty InlineArray is documented as having a one byte alignment.

For an element type with alignment > 1, accessing the span property of an empty InlineArray fails at runtime due to a violation of the alignment precondition used by Span which expects the base pointer to be aligned for the element type.

Likely either Span needs to relax this precondition for empty spans or InlineArray needs to provide a nil base address when creating the Span if it is empty.

Reproduction

func crash() {
    let array: [0 of Int] = []
    // Fatal error: baseAddress must be properly aligned to access Element
    let span = array.span
}

crash()

Stack dump

n/a

Expected behavior

It should be possible to get a span for an empty InlineArray.

Environment

Xcode 26.1
swift-driver version: 1.127.14.1 Apple Swift version 6.2.1 (swiftlang-6.2.1.4.8 clang-1700.4.4.1)

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.crashBug: A crash, i.e., an abnormal termination of softwaretriage neededThis issue needs more specific labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions