Compiler segmentation fault when @objc protocol optional func uses a CGRect as parameter

Originator:andrea.mazzini
Number:rdar://25109211 Date Originated:11-Mar-2016 04:12 PM
Status:Resolved Resolved:
Product:Developer Tools Product Version:7.2.1 (7C1002)
Classification: Reproducible:Yes
 
Summary:
When creating in Swift a protocol bridged with Objective-C with an optional func providing a parameter of type CGRect, calling this func with optional chaining causes the compiler to segfault.

Steps to Reproduce:
1. Create a Swift protocol bridged with Objective-C:
@objc protocol SomeProtocol {
    optional func willUpdateFrame(frame: CGRect)
}

2. Call the optional function on an optional delegate implementing that protocol:

class SomeClass {
    var delegate: SomeProtocol?

    func updateFrame() {
        delegate?.willUpdateFrame?(CGRect.zero)
    }
}

Expected Results:
Source should compile

Actual Results:
Segmentation fault with the following stack trace:
0  swift                    0x0000000107602fbb llvm::sys::PrintStackTrace(__sFILE*) + 43
1  swift                    0x00000001076036fb SignalHandler(int) + 379
2  libsystem_platform.dylib 0x00007fff9a96f52a _sigtramp + 26
3  swift                    0x00000001074a353e llvm::StringMap<llvm::Value*, llvm::MallocAllocator>::insert(std::__1::pair<llvm::StringRef, llvm::Value*>) + 142
4  swift                    0x000000010745df9c llvm::StoreInst::StoreInst(llvm::Value*, llvm::Value*, bool, llvm::Instruction*) + 60
5  swift                    0x000000010715a474 llvm::IRBuilder<true, llvm::ConstantFolder, llvm::IRBuilderDefaultInserter<true> >::CreateStore(llvm::Value*, llvm::Value*, bool) + 68
6  swift                    0x00000001057f0d59 swift::irgen::SingleScalarTypeInfo<(anonymous namespace)::PrimitiveTypeInfo, swift::irgen::LoadableTypeInfo>::initialize(swift::irgen::IRGenFunction&, swift::irgen::Explosion&, swift::irgen::Address) const + 41
7  swift                    0x00000001057e44bc swift::irgen::SequentialTypeInfo<(anonymous namespace)::LoadableStructTypeInfo, swift::irgen::LoadableTypeInfo, (anonymous namespace)::StructFieldInfo, true>::initialize(swift::irgen::IRGenFunction&, swift::irgen::Explosion&, swift::irgen::Address) const + 220
8  swift                    0x00000001057e44bc swift::irgen::SequentialTypeInfo<(anonymous namespace)::LoadableStructTypeInfo, swift::irgen::LoadableTypeInfo, (anonymous namespace)::StructFieldInfo, true>::initialize(swift::irgen::IRGenFunction&, swift::irgen::Explosion&, swift::irgen::Address) const + 220
9  swift                    0x00000001057e2dcc swift::irgen::SequentialTypeInfo<(anonymous namespace)::ClangRecordTypeInfo, swift::irgen::LoadableTypeInfo, (anonymous namespace)::ClangFieldInfo, true>::initialize(swift::irgen::IRGenFunction&, swift::irgen::Explosion&, swift::irgen::Address) const + 236
10 swift                    0x00000001057e2dcc swift::irgen::SequentialTypeInfo<(anonymous namespace)::ClangRecordTypeInfo, swift::irgen::LoadableTypeInfo, (anonymous namespace)::ClangFieldInfo, true>::initialize(swift::irgen::IRGenFunction&, swift::irgen::Explosion&, swift::irgen::Address) const + 236
11 swift                    0x0000000105782871 swift::irgen::CallEmission::setArgs(swift::irgen::Explosion&, llvm::ArrayRef<swift::SILParameterInfo>, swift::irgen::WitnessMetadata*) + 1777
12 swift                    0x00000001057aabe9 swift::irgen::emitObjCPartialApplication(swift::irgen::IRGenFunction&, swift::SILDeclRef, swift::CanTypeWrapper<swift::SILFunctionType>, swift::CanTypeWrapper<swift::SILFunctionType>, llvm::Value*, swift::SILType, swift::irgen::Explosion&) + 1945
13 swift                    0x0000000105819c75 swift::SILVisitor<(anonymous namespace)::IRGenSILFunction, void>::visit(swift::ValueBase*) + 32117
14 swift                    0x000000010580e9ad swift::irgen::IRGenModule::emitSILFunction(swift::SILFunction*) + 10973
15 swift                    0x0000000105774b58 swift::irgen::IRGenModuleDispatcher::emitGlobalTopLevel() + 376
16 swift                    0x00000001057f53a4 performIRGeneration(swift::IRGenOptions&, swift::ModuleDecl*, swift::SILModule*, llvm::StringRef, llvm::LLVMContext&, swift::SourceFile*, unsigned int) + 788
17 swift                    0x00000001057f5830 swift::performIRGeneration(swift::IRGenOptions&, swift::SourceFile&, swift::SILModule*, llvm::StringRef, llvm::LLVMContext&, unsigned int) + 64
18 swift                    0x00000001056f4265 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&) + 13701
19 swift                    0x00000001056f0ad3 frontend_main(llvm::ArrayRef<char const*>, char const*, void*) + 2691
20 swift                    0x00000001056ed154 main + 2324
21 libdyld.dylib            0x00007fff9ae325ad start + 1
22 libdyld.dylib            0x000000000000003b start + 1696389775

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!