Swift: crash with CFBinaryHeapCallBacks
| Originator: | jtbandes | ||
| Number: | rdar://23549284 | Date Originated: | 11/14/2015 |
| Status: | Open | Resolved: | |
| Product: | Developer Tools | Product Version: | |
| Classification: | Crash/Hang/Data Loss | Reproducible: | Always |
Summary:
The following code crashes the Swift compiler:
Steps to Reproduce:
import Foundation
class BinaryHeap<T: AnyObject where T: Comparable>
{
let heap: CFBinaryHeap
init() {
var callbacks = CFBinaryHeapCallBacks(
version: 0,
retain: { _, obj in
Unmanaged<T>.fromOpaque(COpaquePointer(obj)).retain()
return obj
},
release: { _, obj in
Unmanaged<T>.fromOpaque(COpaquePointer(obj)).release()
},
copyDescription: { obj in
let o = Unmanaged<T>.fromOpaque(COpaquePointer(obj)).takeUnretainedValue()
return Unmanaged.passRetained(String(o) as CFString)
},
compare: { obj1, obj2, _ in
let o1 = Unmanaged<T>.fromOpaque(COpaquePointer(obj1)).takeUnretainedValue()
let o2 = Unmanaged<T>.fromOpaque(COpaquePointer(obj2)).takeUnretainedValue()
if o1 == o2 { return .CompareEqualTo }
if o1 < o2 { return .CompareLessThan }
return .CompareGreaterThan
}
)
heap = CFBinaryHeapCreate(nil, 0, &callbacks, nil)
}
}
Expected Results:
No crash.
Actual Results:
Segfault:
0 swift 0x0000000105ddc33b llvm::sys::PrintStackTrace(__sFILE*) + 43
1 swift 0x0000000105ddca7b SignalHandler(int) + 379
2 libsystem_platform.dylib 0x00007fff9d65beaa _sigtramp + 26
3 libsystem_platform.dylib 0x0000000000000003 _sigtramp + 1654276467
4 swift 0x0000000103fac4ab swift::irgen::emitPolymorphicArguments(swift::irgen::IRGenFunction&, swift::CanTypeWrapper<swift::SILFunctionType>, swift::CanTypeWrapper<swift::SILFunctionType>, llvm::ArrayRef<swift::Substitution>, swift::irgen::WitnessMetadata*, swift::irgen::Explosion&) + 587
5 swift 0x0000000103ff90ac (anonymous namespace)::IRGenSILFunction::visitFullApplySite(swift::FullApplySite) + 2172
6 swift 0x0000000103feabad swift::irgen::IRGenModule::emitSILFunction(swift::SILFunction*) + 10973
7 swift 0x0000000103f51253 swift::irgen::IRGenModuleDispatcher::emitLazyDefinitions() + 307
8 swift 0x0000000103fd169a performIRGeneration(swift::IRGenOptions&, swift::ModuleDecl*, swift::SILModule*, llvm::StringRef, llvm::LLVMContext&, swift::SourceFile*, unsigned int) + 1034
9 swift 0x0000000103fd1a30 swift::performIRGeneration(swift::IRGenOptions&, swift::SourceFile&, swift::SILModule*, llvm::StringRef, llvm::LLVMContext&, unsigned int) + 64
10 swift 0x0000000103ed0465 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&) + 13701
11 swift 0x0000000103ecccd3 frontend_main(llvm::ArrayRef<char const*>, char const*, void*) + 2691
12 swift 0x0000000103ec9354 main + 2324
13 libdyld.dylib 0x00007fff9e79f5ad start + 1
14 libdyld.dylib 0x000000000000000f start + 1636174435
Stack dump:
0. Program arguments: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c -primary-file - -target x86_64-apple-darwin15.2.0 -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk -color-diagnostics -module-name main -o /var/folders/lp/hlnmlhtn79s4qvxx8c7bppbw0000gn/T/--d9fefa.o
1. While emitting IR SIL function @_TToFFC4main10BinaryHeapcuRq_Ss9AnyObjectq_Ss10Comparable_FMGS0_q__FT_GS0_q__U2_FTGVSs13UnsafePointerT__GS3_T__GVSs20UnsafeMutablePointerT___OSC18CFComparisonResult for expression at [<stdin>:20:22 - line:26:13] RangeText="{ obj1, obj2, _ in
let o1 = Unmanaged<T>.fromOpaque(COpaquePointer(obj1)).takeUnretainedValue()
let o2 = Unmanaged<T>.fromOpaque(COpaquePointer(obj2)).takeUnretainedValue()
if o1 == o2 { return .CompareEqualTo }
if o1 < o2 { return .CompareLessThan }
return .CompareGreaterThan
}"
Version:
Xcode 7.2 beta (7C46t)
OS X 10.11.2 (15C40a)
Configuration:
Apple Swift version 2.1 (swiftlang-700.1.101.6 clang-700.1.76)
Target: x86_64-apple-darwin15.2.0
Comments
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!