Xcode 7.1 (7B91b): [Swift] Creating a @convention(c) closure using a literal closure in a generic context crashes the compiler

Originator:janoschhildebrand
Number:rdar://23345835 Date Originated:31-Oct-2015
Status:Duplicate of 22470105 (Open) Resolved:
Product:Developer Tools Product Version:Xcode 7.1 (7B91b)
Classification:Serious Bug Reproducible:Always
 
It is not possible to use a generic function/closure as a @convention(c) argument.

In most cases trying to do so results in an error message, however when using a closure literal in a generic context to create a @convention(c) closure, the Swift compiler crashes.

The following example demonstrates this issue:

// Function that requires a @convention(c) closure
func function(s: @convention(c) () -> ()) {
}

func genericFunction<T>(el: T) {
    // Create one using closure literal in a generic context
    function() { }
}

// -> Command failed due to signal: Segmentation fault: 11


An example project is attached.

Steps to Reproduce:
Open & build the attached project.

Expected Results:
If the closure literal does not not depend on / use the generic context in any way, this should ideally compile successfully.

If the closure literal makes use of the generic context it is in, an error message should be emitted.

Actual Results:
The compiler crashes.

Stack trace:

0  swift                    0x00000001029f933b llvm::sys::PrintStackTrace(__sFILE*) + 43
1  swift                    0x00000001029f9a7b SignalHandler(int) + 379
2  libsystem_platform.dylib 0x00007fff9c53c52a _sigtramp + 26
3  libsystem_platform.dylib 0x0000001d00726573 _sigtramp + 1679728739
4  swift                    0x0000000100bc94ab 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                    0x0000000100c160ac (anonymous namespace)::IRGenSILFunction::visitFullApplySite(swift::FullApplySite) + 2172
6  swift                    0x0000000100c07bad swift::irgen::IRGenModule::emitSILFunction(swift::SILFunction*) + 10973
7  swift                    0x0000000100b6e253 swift::irgen::IRGenModuleDispatcher::emitLazyDefinitions() + 307
8  swift                    0x0000000100bee69a performIRGeneration(swift::IRGenOptions&, swift::ModuleDecl*, swift::SILModule*, llvm::StringRef, llvm::LLVMContext&, swift::SourceFile*, unsigned int) + 1034
9  swift                    0x0000000100beea30 swift::performIRGeneration(swift::IRGenOptions&, swift::SourceFile&, swift::SILModule*, llvm::StringRef, llvm::LLVMContext&, unsigned int) + 64
10 swift                    0x0000000100aed465 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&) + 13701
11 swift                    0x0000000100ae9cd3 frontend_main(llvm::ArrayRef<char const*>, char const*, void*) + 2691
12 swift                    0x0000000100ae6354 main + 2324
13 libdyld.dylib            0x00007fff9091e5ad start + 1


1.	While emitting IR SIL function @_TToFF3Bug15genericFunctionurFq_T_U_FT_T_ for expression at [/Users/janoschhildebrand/Desktop/Bug/Bug/main.swift:15:16 - line:15:18] RangeText="{ }"

Version:
Xcode 7.1 (7B91b)
Apple Swift version 2.1 (swiftlang-700.1.101.6 clang-700.1.76)
OS X 10.11.1 (15B42)

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!