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

Miscompile in Swift 3.2 results in zombie message (regression from 3.1)

    XMLWordPrintable

    Details

      Description

      Consider the following code, which runs error-free in Swift 3.1, but results in a runtime crash in Swift 3.2 and Swift 4:

      import Foundation
      
      struct S {
        var str = UUID().uuidString
      }
      
      func go() {
          var s = S()
          s = S()
      
          _ = DispatchQueue.global(qos: .default).async {
              print(s.str)
          }
      }
      
      go()
      sleep(1)
      

      This crashes using swift that ships with Xcode 9 beta 1 by running it in the following ways:
      swift -swift-version 3 file.swift
      swift file.swift

      Output from the program:

      0CC3D5F2-3F86-4B6E-88B6-181891DEF66C
      0 swift 0x00000001110823aa PrintStackTraceSignalHandler(void*) + 42
      1 swift 0x00000001110817e6 SignalHandler(int) + 662
      2 libsystem_platform.dylib 0x00007fffb6d64b3a _sigtramp + 26
      3 libsystem_platform.dylib 000000000000000000 _sigtramp + 1227470048
      4 libsystem_platform.dylib 0x0000000113ad1744 _sigtramp + 1557580836
      5 libswiftCore.dylib 0x00000001167a6770 _swift_release_dealloc + 16
      6 libswiftCore.dylib 0x0000000113ad1894 _swift_release_dealloc + 4247957812
      7 libsystem_blocks.dylib 0x00007fffb6b89952 _Block_release + 102
      8 libdispatch.dylib 0x00007fffb6b1f8fc _dispatch_client_callout + 8
      9 libdispatch.dylib 0x00007fffb6b2e196 _dispatch_queue_override_invoke + 743
      10 libdispatch.dylib 0x00007fffb6b216b5 _dispatch_root_queue_drain + 476
      11 libdispatch.dylib 0x00007fffb6b2148c _dispatch_worker_thread3 + 99
      12 libsystem_pthread.dylib 0x00007fffb6d6e5a2 _pthread_wqthread + 1299
      13 libsystem_pthread.dylib 0x00007fffb6d6e07d start_wqthread + 13
      Killed: 9

      In Instruments, you can see that the string held by s is released an extra time.

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              benasher44 Ben A
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: