swiftlang/swift

[SR-3207] Segfault with Obj-C parameter of (NSError* __autoreleasing __nonnull * __nullable)

Open

#45.795 aperta il 14 nov 2016

Vedi su GitHub
 (5 commenti) (0 reazioni) (0 assegnatari)Swift (10.719 fork)batch import
bugcompilercrashgood first issue

Metriche repository

Star
 (69.989 star)
Metriche merge PR
 (Merge medio 8g 17h) (510 PR mergiate in 30 g)

Descrizione

Previous ID SR-3207
Radar None
Original Reporter @ZevEisenberg
Type Bug

Attachment: Download

Xcode 8.1 (8B62), command line app template (attached)

Votes 1
Component/s Compiler
Labels Bug, ClangImporter, CompilerCrash, StarterBug
Assignee None
Priority Medium

md5: a83cf30f388c234c30c5851dc159b2e4

is duplicated by:

  • SR-3272 Segmentation fault: 11 when referencing Objective-C method with NSError ** argument having wrong nullability specifier

Issue Description:

With the following setup:

MyObject.h:

@import Foundation;

@interface MyObject: NSObject

- (BOOL)segFaultingMethod:(NSError* __autoreleasing __nonnull * __nullable)error;

@end

MyObject.m:

#import "MyObject.h"

@implementation MyObject

- (BOOL)segFaultingMethod:(NSError *__autoreleasing *)error
{
    return YES;
}

@end

main.swift

import Foundation

do {
    try MyObject().segFaultingMethod()
}
catch {
    
}

Compilation gets the following crash:

0  swift                    0x000000010d6fea3d PrintStackTraceSignalHandler(void*) + 45
1  swift                    0x000000010d6fe466 SignalHandler(int) + 470
2  libsystem_platform.dylib 0x00007fff9be44bba _sigtramp + 26
3  libsystem_platform.dylib 0x00007fba4eedd050 _sigtramp + 3003745456
4  swift                    0x000000010abfbb28 swift::irgen::IRGenModule::emitSILFunction(swift::SILFunction*) + 9336
5  swift                    0x000000010ab1d231 swift::irgen::IRGenerator::emitGlobalTopLevel() + 1329
6  swift                    0x000000010abe134b performIRGeneration(swift::IRGenOptions&, swift::ModuleDecl*, swift::SILModule*, llvm::StringRef, llvm::LLVMContext&, swift::SourceFile*, unsigned int) + 1259
7  swift                    0x000000010aaacc19 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*) + 23705
8  swift                    0x000000010aaa4f70 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 17856
9  swift                    0x000000010aa6193e main + 8302
10 libdyld.dylib            0x00007fff9bc37255 start + 1
Stack dump:
0.  Program arguments: /Applications/Xcode_8.1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c -primary-file /Users/zev/Desktop/SegFaulter/SegFaulter/main.swift -target x86_64-apple-macosx10.12 -enable-objc-interop -sdk /Applications/Xcode_8.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk -I /Users/zev/Library/Developer/Xcode/DerivedData/SegFaulter-dstsgxcgfdmhyygoixtufebsgxrq/Build/Products/Debug -F /Users/zev/Library/Developer/Xcode/DerivedData/SegFaulter-dstsgxcgfdmhyygoixtufebsgxrq/Build/Products/Debug -enable-testing -g -import-objc-header /Users/zev/Desktop/SegFaulter/SegFaulter/SegFaulter-Bridging-Header.h -module-cache-path /Users/zev/Library/Developer/Xcode/DerivedData/ModuleCache -serialize-debugging-options -Xcc -I/Users/zev/Library/Developer/Xcode/DerivedData/SegFaulter-dstsgxcgfdmhyygoixtufebsgxrq/Build/Intermediates/SegFaulter.build/Debug/SegFaulter.build/swift-overrides.hmap -Xcc -iquote -Xcc /Users/zev/Library/Developer/Xcode/DerivedData/SegFaulter-dstsgxcgfdmhyygoixtufebsgxrq/Build/Intermediates/SegFaulter.build/Debug/SegFaulter.build/SegFaulter-generated-files.hmap -Xcc -I/Users/zev/Library/Developer/Xcode/DerivedData/SegFaulter-dstsgxcgfdmhyygoixtufebsgxrq/Build/Intermediates/SegFaulter.build/Debug/SegFaulter.build/SegFaulter-own-target-headers.hmap -Xcc -I/Users/zev/Library/Developer/Xcode/DerivedData/SegFaulter-dstsgxcgfdmhyygoixtufebsgxrq/Build/Intermediates/SegFaulter.build/Debug/SegFaulter.build/SegFaulter-all-target-headers.hmap -Xcc -iquote -Xcc /Users/zev/Library/Developer/Xcode/DerivedData/SegFaulter-dstsgxcgfdmhyygoixtufebsgxrq/Build/Intermediates/SegFaulter.build/Debug/SegFaulter.build/SegFaulter-project-headers.hmap -Xcc -I/Users/zev/Library/Developer/Xcode/DerivedData/SegFaulter-dstsgxcgfdmhyygoixtufebsgxrq/Build/Products/Debug/include -Xcc -I/Users/zev/Library/Developer/Xcode/DerivedData/SegFaulter-dstsgxcgfdmhyygoixtufebsgxrq/Build/Intermediates/SegFaulter.build/Debug/SegFaulter.build/DerivedSources/x86_64 -Xcc -I/Users/zev/Library/Developer/Xcode/DerivedData/SegFaulter-dstsgxcgfdmhyygoixtufebsgxrq/Build/Intermediates/SegFaulter.build/Debug/SegFaulter.build/DerivedSources -Xcc -DDEBUG=1 -Xcc -working-directory/Users/zev/Desktop/SegFaulter -emit-module-doc-path /Users/zev/Library/Developer/Xcode/DerivedData/SegFaulter-dstsgxcgfdmhyygoixtufebsgxrq/Build/Intermediates/SegFaulter.build/Debug/SegFaulter.build/Objects-normal/x86_64/main~partial.swiftdoc -Onone -module-name SegFaulter -emit-module-path /Users/zev/Library/Developer/Xcode/DerivedData/SegFaulter-dstsgxcgfdmhyygoixtufebsgxrq/Build/Intermediates/SegFaulter.build/Debug/SegFaulter.build/Objects-normal/x86_64/main~partial.swiftmodule -serialize-diagnostics-path /Users/zev/Library/Developer/Xcode/DerivedData/SegFaulter-dstsgxcgfdmhyygoixtufebsgxrq/Build/Intermediates/SegFaulter.build/Debug/SegFaulter.build/Objects-normal/x86_64/main.dia -emit-dependencies-path /Users/zev/Library/Developer/Xcode/DerivedData/SegFaulter-dstsgxcgfdmhyygoixtufebsgxrq/Build/Intermediates/SegFaulter.build/Debug/SegFaulter.build/Objects-normal/x86_64/main.d -emit-reference-dependencies-path /Users/zev/Library/Developer/Xcode/DerivedData/SegFaulter-dstsgxcgfdmhyygoixtufebsgxrq/Build/Intermediates/SegFaulter.build/Debug/SegFaulter.build/Objects-normal/x86_64/main.swiftdeps -o /Users/zev/Library/Developer/Xcode/DerivedData/SegFaulter-dstsgxcgfdmhyygoixtufebsgxrq/Build/Intermediates/SegFaulter.build/Debug/SegFaulter.build/Objects-normal/x86_64/main.o 
1.  While emitting IR SIL function @main

The issue appears to be that the __nullable and __nonnull annotations are transposed, which is an easy mistake to make. The compiler should warn, error, and/or provide a fix-it, rather than crashing.

Guida contributor