Uploaded image for project: 'Swift'
  1. Swift
  2. SR-11336

Array + key-path crasher due to `-enable-ownership-stripping-after-serialization` for swiftCore

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Medium
    • Resolution: Done
    • Component/s: Compiler
    • Labels:

      Description

      protocol SomeProtocol {}
      func SR_11336(_ array: Array<Int>) {
        let keyPaths: [PartialKeyPath<Array>] = array.indices.map { \Array<Int>[$0] }
        for kp in keyPaths {
          _ = array[keyPath: kp] is SomeProtocol
        }
      }
      let array: [Int] = [1000, 1]
      // Crashes only if `array` contains 2 or more elements.
      SR_11336(array)
      

      The cause is enabling -Xfrontend -enable-ownership-stripping-after-serialization for swiftCore.

      This was done in https://github.com/apple/swift/commit/4ecab471909a8bb101afe6f7c40f5ae7f492f17c (for swiftCore), then later in https://github.com/apple/swift/commit/447f00892af767cf9426f82764cbdbc6f087956c (for swiftCore and overlays).

      Reproduce:

      $ swift sr-11336.swift
      [1]    96610 illegal hardware instruction  $SWIFT_BIN/swift sr-11336-2.swift
      

      Weirdly, swiftc sr-11336.swift && ./sr-11336 doesn't crash.

      $ swiftc sr-11336.swift && ./sr-11336
      # Succeeds, no crash.
      

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            pschuh Parker Schuh
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: