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-14830] Xcode 12.5 causes release build to crash, same code works in 12.4 #57177

Open
swift-ci opened this issue Jun 26, 2021 · 1 comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@swift-ci
Copy link
Collaborator

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)

@swift-ci
Copy link
Collaborator Author

Comment by Jeff Lockhart (JIRA)

I discovered the cause. There's an extra call to .compactMap { $0 } that is redundant. In debug builds and previously in release builds in Xcode 12.4, this just returns the same array. But in release builds in Xcode 12.5 it crashes.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
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
Projects
None yet
Development

No branches or pull requests

1 participant