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-12423] App built in release mode w/ 5.2/Xcode 11.14 segfaults #54862

Open
swift-ci opened this issue Mar 26, 2020 · 4 comments
Open

[SR-12423] App built in release mode w/ 5.2/Xcode 11.14 segfaults #54862

swift-ci opened this issue Mar 26, 2020 · 4 comments
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-12423
Radar rdar://problem/60923904
Original Reporter helge (JIRA User)
Type Bug
Environment

Mac OS X 10.15.4 (19E266)
Xcode Version 11.4 (11E146)

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

md5: 4dd2006f4b10b1dff9a4b2f7f9a6ee61

Issue Description:

Debug works fine, so probably an optimiser issue.

backtrace within Xcode

Marzipan was compiled with optimization - stepping may behave oddly; variables may not be available.
* thread #​1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x20)
    frame #&#8203;0: 0x00007fff6df81b90 libswiftCore.dylib`Swift.(_stringCompareFastUTF8Abnormal in _835F230159459CFFE280B5F8E69D8077)(_: Swift.UnsafeBufferPointer<Swift.UInt8>, _: Swift.UnsafeBufferPointer<Swift.UInt8>, expecting: Swift._StringComparisonResult) -> Swift.Bool + 48
    frame #&#8203;1: 0x00000001006f812b Marzipan`specialized thunk for @escaping @callee_guaranteed (@guaranteed A, @guaranteed A) -> (@unowned Bool) [inlined] MMM.(compareConversation in _24F12AD896879B222B96E7000F788E5D)(lhs: PPP, rhs: PPP) -> Swift.Bool at <compiler-generated>:0 [opt]
    frame #&#8203;2: 0x00000001006f8120 Marzipan`specialized thunk for @escaping @callee_guaranteed (@guaranteed A, @guaranteed A) -> (@unowned Bool) [inlined] function signature specialization <Arg[2] = [Constant Propagated Function : MMM.(compareConversation in _24F12AD896879B222B96E7000F788E5D)(lhs: PPP, rhs: PPP) -> Swift.Bool]> of reabstraction thunk helper <A where A: PPP, A: Swift.Equatable> from @escaping @callee_guaranteed (@guaranteed PPP, @guaranteed PPP) -> (@unowned Swift.Bool) to @escaping @callee_guaranteed (@guaranteed A, @guaranteed A) -> (@unowned Swift.Bool) at <compiler-generated>:0 [opt]
    frame #&#8203;3: 0x00000001006f8120 Marzipan`specialized thunk for @escaping @callee_guaranteed (@guaranteed A, @guaranteed A) -> (@unowned Bool) at <compiler-generated>:0 [opt]
    frame #&#8203;4: 0x000000010069c7eb Marzipan`specialized MutableCollection<>._insertionSort(within:sortedEnd:by:) at <compiler-generated>:0 [opt]
    frame #&#8203;5: 0x0000000100699279 Marzipan`merged generic specialization <XXX> of Swift.UnsafeMutableBufferPointer._stableSortImpl(by: (A, A) throws -> Swift.Bool) throws -> () + 169
    frame #&#8203;6: 0x0000000100694547 Marzipan`specialized MutableCollection<>.sort(by:) [inlined] generic specialization <Swift.ContiguousArray<XXX>> of closure #&#8203;1 (inout Swift.UnsafeMutableBufferPointer<A.Swift.Sequence.Element>) throws -> () in (extension in Swift):Swift.MutableCollection< where A: Swift.RandomAccessCollection>.sort(by: (A.Swift.Sequence.Element, A.Swift.Sequence.Element) throws -> Swift.Bool) throws -> () at <compiler-generated>:0 [opt]
    frame #&#8203;7: 0x000000010069451d Marzipan`specialized MutableCollection<>.sort(by:) [inlined] inlined generic function <Swift.ContiguousArray<XXX>> of reabstraction thunk helper <A where A: Swift.MutableCollection, A: Swift.RandomAccessCollection> from @callee_guaranteed (@inout Swift.UnsafeMutableBufferPointer<A.Swift.Sequence.Element>) -> (@error @owned Swift.Error) to @escaping @callee_guaranteed (@inout Swift.UnsafeMutableBufferPointer<A.Swift.Sequence.Element>) -> (@out (), @error @owned Swift.Error) at <compiler-generated>:0 [opt]
    frame #&#8203;8: 0x000000010069451d Marzipan`specialized MutableCollection<>.sort(by:) [inlined] generic specialization <XXX, ()> of closure #&#8203;1 (inout Swift.UnsafeMutableBufferPointer<A>) throws -> A1 in Swift.ContiguousArray._withUnsafeMutableBufferPointerIfSupported<A>((inout Swift.UnsafeMutableBufferPointer<A>) throws -> A1) throws -> Swift.Optional<A1> at <compiler-generated>:0 [opt]
    frame #&#8203;9: 0x000000010069451d Marzipan`specialized MutableCollection<>.sort(by:) [inlined] generic specialization <XXX, ()> of Swift.ContiguousArray._withUnsafeMutableBufferPointerIfSupported<A>((inout Swift.UnsafeMutableBufferPointer<A>) throws -> A1) throws -> Swift.Optional<A1> at <compiler-generated>:0 [opt]
    frame #&#8203;10: 0x000000010069451d Marzipan`specialized MutableCollection<>.sort(by:) [inlined] inlined generic function <XXX, ()> of protocol witness for Swift.MutableCollection._withUnsafeMutableBufferPointerIfSupported<A>((inout Swift.UnsafeMutableBufferPointer<A.Element>) throws -> A1) throws -> Swift.Optional<A1> in conformance Swift.ContiguousArray<A> : Swift.MutableCollection in Swift at <compiler-generated>:0 [opt]
    frame #&#8203;11: 0x000000010069451d Marzipan`specialized MutableCollection<>.sort(by:) at <compiler-generated>:0 [opt]
    frame #&#8203;12: 0x000000010068ff62 Marzipan`specialized AAA.arrangeObjects() [inlined] generic specialization <Swift.Dictionary<YYY, XXX>.Values> of (extension in Swift):Swift.Sequence.sorted(by: (A.Element, A.Element) throws -> Swift.Bool) throws -> Swift.Array<A.Element> at <compiler-generated>:0 [opt]

relevant code section

  private func arrangeObjects() {
    assertMainQueue()
    matches.removeAll()
    
    guard let matchPrefix = matchPrefix else {
      if arrangedObjects.isEmpty { return }
      arrangedObjects.removeAll()
      return emit()
    }
    
    if matchPrefix.isEmpty {
      if let sort = sortFunction {
        arrangedObjects = allObjects.values.sorted(by: sort)
      }...

same machine, app crash report preamble

Path:                  /Applications/Marzipan.app/Contents/MacOS/Marzipan
Identifier:            de.zeezide.swift.see1.marzipan
Version:               0.5 (37)
Code Type:             X86-64 (Native)
Parent Process:        ??? [1]
Responsible:           Marzipan [9811]
User ID:               501

Date/Time:             2020-03-26 17:07:47.211 +0100
OS Version:            Mac OS X 10.15.4 (19E266)
Report Version:        12
Bridge OS Version:     4.4 (17P4263)
Anonymous UUID:        3D9A839B-4E7E-4342-4336-BCEB6A848EDD


Time Awake Since Boot: 95000 seconds

System Integrity Protection: enabled

Crashed Thread:        0  Dispatch queue: com.apple.main-thread

Exception Type:        EXC_BAD_ACCESS (SIGSEGV)
Exception Codes:       KERN_INVALID_ADDRESS at 0x0000000000000020
Exception Note:        EXC_CORPSE_NOTIFY

Termination Signal:    Segmentation fault: 11
Termination Reason:    Namespace SIGNAL, Code 0xb
Terminating Process:   exc handler [9811]
@jckarter
Copy link
Member

@swift-ci create

@swift-ci
Copy link
Collaborator Author

Comment by Helge Heß (JIRA)

I managed to avoid the crash by slapping an `@_optimized(none)` at the initializer which uses the sort function:

public final class XYZBlubLiveQuery
                     <ValueType: PPP & Equatable>
                   : XYZPrefixLiveQuery<ValueType>
{
  @_optimize(none) // https://bugs.swift.org/browse/SR-12423
  internal init(initialState state: [ SomeIDStruct : ValueType ]) {
    super.init(initialState: state, matchPrefix: "",
               sortFunction: compareConversation)
  }

the `compareConversation` function is what is used in the `arrangeObjects` shown above as `sort`.

@eeckstein
Copy link
Member

helge (JIRA User) Is it possible that you attach a reduced test case so that we can reproduce the issue?

@swift-ci
Copy link
Collaborator Author

Comment by Helge Heß (JIRA)

That stuff is spanning things from at least 3 modules, it'll be a significant amount of work to extract that. I'll see whether I can find the time, but I can't promise that.

@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

3 participants