Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ZevEisenberg opened this issue Nov 14, 2016 · 5 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself crash Bug: A crash, i.e., an abnormal termination of software good first issue Good for newcomers

Comments

@ZevEisenberg
Copy link
Contributor

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

Attachment: Download

Environment

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

Additional Detail from JIRA
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.

@belkadan
Copy link
Contributor

We should probably just refuse to import this as a throwing method at all.

@belkadan
Copy link
Contributor

That said, the Swift compiler shouldn't really be responsible for diagnosing Objective-C mistakes. Unfortunately, Objective-C doesn't really have a way to know that this is a mistake, but maybe a warning would be okay anyway.

@swift-ci
Copy link
Collaborator

Comment by David Sweeris (JIRA)

This is probably one of those noob questions... How do you get swift to import objc stuff from the command line? All but one of the resources I could find on the topic assume you're compiling with Xcode, and I just can't find the incantation to pass to swift to even get this to even try to compile. Right now, under "Arguments Passed On Launch", I've got "-frontend -c /path/to/main.swift -import-objc-header /path/to/SegFaulter-Bridging-Header.h /path/to/MyObject.m -F /System/Library/Frameworks/Foundation -I/usr/include", and the output is:

/path/to/SegFaulter-Bridging-Header.h:1:9: note: in file included from /path/to/SegFaulter-Bridging-Header.h:1:
#import "MyObject.h"
        ^
/path/to/MyObject.h:1:9: error: module 'Foundation' not found
@import Foundation;
        ^
<unknown>:0: error: failed to import bridging header '/path/to/SegFaulter-Bridging-Header.h'
Program ended with exit code: 1

@belkadan
Copy link
Contributor

That's pretty much it, but -F is a search path option, so you want to point it at the directory that contains frameworks.

…wait, why do you have a .m file in there?

@swift-ci
Copy link
Collaborator

Comment by David Sweeris (JIRA)

Do the .m files not need to be compiled? The output is the same if I remove it.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added the crash Bug: A crash, i.e., an abnormal termination of software label Dec 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself crash Bug: A crash, i.e., an abnormal termination of software good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

4 participants