Skip to content

[SR-14830] Xcode 12.5 causes release build to crash, same code works in 12.4 #57177

@swift-ci

Description

@swift-ci
Previous ID SR-14830
Radar None
Original Reporter jefflockhart (JIRA User)
Type Bug
Environment

Xcode 12.5, multiple Macbook computers

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

md5: eaa39405d59c6739be65f4bf2461e5f1

Issue Description:

After upgrading from Xcode 12.4 to 12.5, we discovered that release builds of our app crashed in the function with<T>(elementsAs: ). This is a summary of the class including that function:

public class ChangedObjs<Element> {

public private(set) var added: \[Element\]?  
public private(set) var updated: \[Element\]?  
public private(set) var toDelete: \[Element\]?

func with\<T\>(elementsAs type: T.Type) -\> ChangedObjs\<T\>? {



    let added = self.added as? \[T\]



    let updated = self.updated as? \[T\]



    let toDelete = self.toDelete as? \[T\]



    let isEmpty = \[added, updated, toDelete\]

        .compactMap  

{ $0 }

        .compactMap { $0 }

        .isEmpty



    if isEmpty { return nil }



    return ChangedObjs\<T\>(added: added, updated: updated, toDelete: toDelete)  
}  

}

It's clear in Xcode 12.5, the function is being optimized as inlined in release builds, as the debugger stack trace indicates it as such. In Xcode 12.4, the function also seems to be inlined, although the debugger refuses to step into the function. Debug builds on both versions of Xcode do not inline the function and don't experience the crash, only release builds on Xcode 12.5.

The crash occurs when stepping through the function after the third line:

let toDelete = self.toDelete as? [T]

with the exception:

Thread 34: EXC_BAD_ACCESS (code=EXC_I386_GPFLT)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itself

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions