Crash when deallocating an unused DispatchSourceTimer

Originator:igeek1
Number:rdar://40269002 Date Originated:15-May-2018 04:41 PM
Status:Open Resolved:
Product:macOS + SDK Product Version:Xcode 9.3.1 (9E501) on macOS 10.13.4 (17E202)
Classification:Crash/Hang/Data Loss Reproducible:Always
 
Summary:
Deallocating an unused DispatchSourceTimer results in a crash.

Steps to Reproduce:
$ cat TimerCrash.swift 
import Dispatch
_ = DispatchSource.makeTimerSource()
$ swift --version
Apple Swift version 4.1 (swiftlang-902.0.48 clang-902.0.37.1)
Target: x86_64-apple-darwin17.5.0
$ swift TimerCrash.swift 
0  swift                    0x0000000111766ffa PrintStackTraceSignalHandler(void*) + 42
1  swift                    0x00000001117663b6 SignalHandler(int) + 966
2  libsystem_platform.dylib 0x00007fff5dfd9f5a _sigtramp + 26
3  libsystem_platform.dylib 0x00007fffda67c4e6 _sigtramp + 2087331238
4  libsystem_platform.dylib 0x0000000115918058 _sigtramp + 3079921944
5  swift                    0x000000010eaa7c0a llvm::MCJIT::runFunction(llvm::Function*, llvm::ArrayRef<llvm::GenericValue>) + 362
6  swift                    0x000000010eaae30c llvm::ExecutionEngine::runFunctionAsMain(llvm::Function*, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&, char const* const*) + 1004
7  swift                    0x000000010ddc9735 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 48709
8  swift                    0x000000010ddbbe64 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 7908
9  swift                    0x000000010dd708b5 main + 18917
10 libdyld.dylib            0x00007fff5dccb015 start + 1
Stack dump:
0.	Program arguments: /Applications/Xcode_9.3.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -interpret TimerCrash.swift -enable-objc-interop -sdk /Applications/Xcode_9.3.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk -color-diagnostics -module-name TimerCrash 
Illegal instruction: 4

Expected Results:
No crash.

Actual Results:
Crash.

Version:
Xcode 9.3.1 (9E501) on macOS 10.13.4 (17E202)

Notes:
Also reproduced with equivalent code in Objective-C, but it was more concise to reproduce it in Swift.

Comments

Apple Developer Relations

No response received. Now closing this bug.

Apple Developer Relations

This issue behaves as intended based on the following: This is because the source has not been activated, which is what the "application specific data" would show in the crash report. Please update your bug report to let us know if this is still an issue for you.

Oh, and this is a regression in Xcode 9.x. It does not crash in Xcode 8.3.


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!