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-11737] Missing throws in @objc protocol conformance with parameter segfaults #54144

Open
tkrajacic opened this issue Nov 8, 2019 · 2 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

Comments

@tkrajacic
Copy link

Previous ID SR-11737
Radar None
Original Reporter @tkrajacic
Type Bug

Attachment: Download

Environment

Xcode 11.2 (11B52)

macOS 10.14.6 (18G103)

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, Crash
Assignee None
Priority Medium

md5: 22541a55f4407eedd50576397ec63f1c

Issue Description:

When forgetting the `throws` keyword when conforming to an @objc protocol the compiler segfaults iff the method has a parameter:

import Foundation

public final class Kermit: NSObject, Muppet {
    public func name(some: String) -> String { "Kermit" }
}

@objc(Muppet)
public protocol Muppet: AnyObject {
    @objc optional func name(some: String) throws -> String
}

Removing the parameter from the function (and protocol) and it compiles. Adding the `throws` to the implementation also works.

A sample project is included for your entertainment pleasure.

crash log:

1.  While generating Objective-C header
2.  While printing 'Kermit' (in module 'ThrowingSegFault')
0  swift                    0x000000010ab30a13 PrintStackTraceSignalHandler(void*) + 51
1  swift                    0x000000010ab301e6 SignalHandler(int) + 358
2  libsystem_platform.dylib 0x00007fff7ec1db5d _sigtramp + 29
3  libsystem_platform.dylib 0x00007ff2c80201b8 _sigtramp + 1228940920
4  swift                    0x0000000106a38760 void (anonymous namespace)::ObjCPrinter::printMembers<false, swift::IteratorRange<swift::DeclIterator> >(swift::IteratorRange<swift::DeclIterator>&&) + 560
5  swift                    0x0000000106a3594c swift::ASTVisitor<(anonymous namespace)::ObjCPrinter, void, void, void, void, void, void>::visit(swift::Decl*) + 7196
6  swift                    0x0000000106787a3c bool llvm::function_ref<bool (llvm::raw_pwrite_stream&)>::callback_fn<printAsObjCIfNeeded(llvm::StringRef, swift::ModuleDecl*, llvm::StringRef, bool)::$_7>(long, llvm::raw_pwrite_stream&) + 6252
7  swift                    0x000000010674a729 swift::withOutputFile(swift::DiagnosticEngine&, llvm::StringRef, llvm::function_ref<bool (llvm::raw_pwrite_stream&)>) + 2569
8  swift                    0x00000001067848a3 emitAnyWholeModulePostTypeCheckSupplementaryOutputs(swift::CompilerInstance&, swift::CompilerInvocation&, bool) + 451
9  swift                    0x000000010677c44a performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 34138
10 swift                    0x00000001067706e4 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 6820
11 swift                    0x00000001066fdbe3 main + 1219
12 libdyld.dylib            0x00007fff7ea323d5 start + 1
error: Segmentation fault: 11 (in target 'ThrowingSegFault' from project 'ThrowingSegFault')
@theblixguy
Copy link
Collaborator

This doesn't crash on master

@beccadax
Copy link
Contributor

I reproduced this on swift-5.1-branch, but not master. With the 11/1 5.1 snapshot, I get:

Assertion failed: (Index < this->size() && "Invalid index!"), function operator[], file /Users/buildnode/jenkins/workspace/oss-swift-5.1-package-osx/llvm/include/llvm/ADT/ArrayRef.h, line 418.
Stack dump:
0.  Program arguments: /Library/Developer/Toolchains/swift-5.1-DEVELOPMENT-SNAPSHOT-2019-11-01-a.xctoolchain/usr/bin/swift -frontend -merge-modules -emit-module /Users/brent/Library/Developer/Xcode/DerivedData/ThrowingSegFault-ctdhitedqwltsacnwezxlpqhruzp/Build/Intermediates.noindex/ThrowingSegFault.build/Debug/ThrowingSegFault.build/Objects-normal/x86_64/Muppet~partial.swiftmodule -parse-as-library -sil-merge-partial-modules -disable-diagnostic-passes -disable-sil-perf-optzns -target x86_64-apple-macos10.14 -enable-objc-interop -sdk /Applications/Xcode-YellowstoneB.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -I /Users/brent/Library/Developer/Xcode/DerivedData/ThrowingSegFault-ctdhitedqwltsacnwezxlpqhruzp/Build/Products/Debug -F /Users/brent/Library/Developer/Xcode/DerivedData/ThrowingSegFault-ctdhitedqwltsacnwezxlpqhruzp/Build/Products/Debug -enable-testing -g -import-underlying-module -module-cache-path /Users/brent/Library/Developer/Xcode/DerivedData/ModuleCache.noindex -swift-version 5 -enforce-exclusivity=checked -Onone -D DEBUG -serialize-debugging-options -enable-anonymous-context-mangled-names -Xcc -I/Users/brent/Library/Developer/Xcode/DerivedData/ThrowingSegFault-ctdhitedqwltsacnwezxlpqhruzp/Build/Intermediates.noindex/ThrowingSegFault.build/Debug/ThrowingSegFault.build/swift-overrides.hmap -Xcc -iquote -Xcc /Users/brent/Library/Developer/Xcode/DerivedData/ThrowingSegFault-ctdhitedqwltsacnwezxlpqhruzp/Build/Intermediates.noindex/ThrowingSegFault.build/Debug/ThrowingSegFault.build/ThrowingSegFault-generated-files.hmap -Xcc -I/Users/brent/Library/Developer/Xcode/DerivedData/ThrowingSegFault-ctdhitedqwltsacnwezxlpqhruzp/Build/Intermediates.noindex/ThrowingSegFault.build/Debug/ThrowingSegFault.build/ThrowingSegFault-own-target-headers.hmap -Xcc -I/Users/brent/Library/Developer/Xcode/DerivedData/ThrowingSegFault-ctdhitedqwltsacnwezxlpqhruzp/Build/Intermediates.noindex/ThrowingSegFault.build/Debug/ThrowingSegFault.build/ThrowingSegFault-all-non-framework-target-headers.hmap -Xcc -ivfsoverlay -Xcc /Users/brent/Library/Developer/Xcode/DerivedData/ThrowingSegFault-ctdhitedqwltsacnwezxlpqhruzp/Build/Intermediates.noindex/ThrowingSegFault.build/Debug/ThrowingSegFault.build/all-product-headers.yaml -Xcc -iquote -Xcc /Users/brent/Library/Developer/Xcode/DerivedData/ThrowingSegFault-ctdhitedqwltsacnwezxlpqhruzp/Build/Intermediates.noindex/ThrowingSegFault.build/Debug/ThrowingSegFault.build/ThrowingSegFault-project-headers.hmap -Xcc -I/Users/brent/Library/Developer/Xcode/DerivedData/ThrowingSegFault-ctdhitedqwltsacnwezxlpqhruzp/Build/Products/Debug/include -Xcc -I/Users/brent/Library/Developer/Xcode/DerivedData/ThrowingSegFault-ctdhitedqwltsacnwezxlpqhruzp/Build/Intermediates.noindex/ThrowingSegFault.build/Debug/ThrowingSegFault.build/DerivedSources-normal/x86_64 -Xcc -I/Users/brent/Library/Developer/Xcode/DerivedData/ThrowingSegFault-ctdhitedqwltsacnwezxlpqhruzp/Build/Intermediates.noindex/ThrowingSegFault.build/Debug/ThrowingSegFault.build/DerivedSources/x86_64 -Xcc -I/Users/brent/Library/Developer/Xcode/DerivedData/ThrowingSegFault-ctdhitedqwltsacnwezxlpqhruzp/Build/Intermediates.noindex/ThrowingSegFault.build/Debug/ThrowingSegFault.build/DerivedSources -Xcc -DDEBUG=1 -Xcc -ivfsoverlay -Xcc /Users/brent/Library/Developer/Xcode/DerivedData/ThrowingSegFault-ctdhitedqwltsacnwezxlpqhruzp/Build/Intermediates.noindex/ThrowingSegFault.build/Debug/ThrowingSegFault.build/unextended-module-overlay.yaml -Xcc -working-directory/Users/brent/Downloads/ThrowingSegFault -emit-module-doc-path /Users/brent/Library/Developer/Xcode/DerivedData/ThrowingSegFault-ctdhitedqwltsacnwezxlpqhruzp/Build/Intermediates.noindex/ThrowingSegFault.build/Debug/ThrowingSegFault.build/Objects-normal/x86_64/ThrowingSegFault.swiftdoc -emit-objc-header-path /Users/brent/Library/Developer/Xcode/DerivedData/ThrowingSegFault-ctdhitedqwltsacnwezxlpqhruzp/Build/Intermediates.noindex/ThrowingSegFault.build/Debug/ThrowingSegFault.build/Objects-normal/x86_64/ThrowingSegFault-Swift.h -module-name ThrowingSegFault -o /Users/brent/Library/Developer/Xcode/DerivedData/ThrowingSegFault-ctdhitedqwltsacnwezxlpqhruzp/Build/Intermediates.noindex/ThrowingSegFault.build/Debug/ThrowingSegFault.build/Objects-normal/x86_64/ThrowingSegFault.swiftmodule 
1.  While generating Objective-C header
2.  While printing 'Kermit' (in module 'ThrowingSegFault')
0  swift                    0x0000000112855105 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 37
1  swift                    0x00000001128543f5 llvm::sys::RunSignalHandlers() + 85
2  swift                    0x00000001128556e8 SignalHandler(int) + 264
3  libsystem_platform.dylib 0x00007fff624abb1d _sigtramp + 29
4  swift                    0x0000000114b7d5c8 cmark_strbuf__initbuf + 128755
5  libsystem_c.dylib        0x00007fff62381a08 abort + 120
6  libsystem_c.dylib        0x00007fff62380cc2 err + 0
7  swift                    0x000000011297a103 (anonymous namespace)::ObjCPrinter::printAbstractFunctionAsMethod(swift::AbstractFunctionDecl*, bool, bool) (.cold.14) + 35
8  swift                    0x000000010f1f3f75 (anonymous namespace)::ObjCPrinter::printAbstractFunctionAsMethod(swift::AbstractFunctionDecl*, bool, bool) + 4773
9  swift                    0x000000010f1f1c20 void (anonymous namespace)::ObjCPrinter::printMembers<false, swift::IteratorRange<swift::DeclIterator> >(swift::IteratorRange<swift::DeclIterator>&&) + 576
10 swift                    0x000000010f1eefa8 swift::ASTVisitor<(anonymous namespace)::ObjCPrinter, void, void, void, void, void, void>::visit(swift::Decl*) + 5992
11 swift                    0x000000010f1de48d swift::printAsObjC(llvm::raw_ostream&, swift::ModuleDecl*, llvm::StringRef, swift::AccessLevel) + 3725
12 swift                    0x000000010f007bc3 void llvm::function_ref<void (llvm::raw_pwrite_stream&)>::callback_fn<swift::withOutputFile(swift::DiagnosticEngine&, llvm::StringRef, llvm::function_ref<bool (llvm::raw_pwrite_stream&)>)::'lambda'(llvm::raw_pwrite_stream&)>(long, llvm::raw_pwrite_stream&) + 19
13 swift                    0x000000010fda2a33 swift::atomicallyWritingToFile(llvm::StringRef, llvm::function_ref<void (llvm::raw_pwrite_stream&)>) + 1491
14 swift                    0x000000010f007b03 swift::withOutputFile(swift::DiagnosticEngine&, llvm::StringRef, llvm::function_ref<bool (llvm::raw_pwrite_stream&)>) + 83
15 swift                    0x000000010f004681 emitAnyWholeModulePostTypeCheckSupplementaryOutputs(swift::CompilerInstance&, swift::CompilerInvocation&, bool) + 257
16 swift                    0x000000010f0023b7 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 12439
17 swift                    0x000000010effe3fa swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 3002
18 swift                    0x000000010efa6ea8 main + 696
19 libdyld.dylib            0x00007fff622aa325 start + 1
20 libdyld.dylib            0x0000000000000049 start + 2648005925
error: Abort trap: 6 (in target 'ThrowingSegFault' from project 'ThrowingSegFault')

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added CompilerCrash and removed crash Bug: A crash, i.e., an abnormal termination of software labels Sep 17, 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
Projects
None yet
Development

No branches or pull requests

4 participants