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-13772] Segfault on compiling test using an @objc protocol with name distinct from the Objective-C generated name #56169

Open
swift-ci opened this issue Oct 24, 2020 · 4 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-13772
Radar rdar://problem/70687408
Original Reporter xy (JIRA User)
Type Bug
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug
Assignee None
Priority Medium

md5: 5c50f1e1acbee2bf3029406aaf11ec8a

Issue Description:

Given an Objective C method like:

  • (NSData *)transactionForTransactionData(_ data: NSData)

... the Swift Compiler would normally generate a Swift function like:

func transaction(for transactionData: Data) -> Data

But, if this Objective C method was auto-created by the Objective C compiler due to an Objective C class Bar's header declaring an implementing an @objc Swift protocol Fooy in another module Foo with a function name like:

@objc func transactionForTransactionData(_ data: NSData) -> NSData

... without actually listing the implementation for it ...

... and if that Bar also inherits from FBSnapshotTestCase ...

... and if there is yet another module Qux in which another class Qux inherits from that Bar, and then if MocQux inherits from Qux, and declares its own local implementations of the Foo protocol methods...

then we get Segmentation Fault 11.

See sample project and README for instructions: https://github.com/1oo7/segfault11.git

Stacktrace:

1. Apple Swift version 5.3 (swiftlang-1200.0.29.2 clang-1200.0.30.1)
2. While looking for 'myNavigationController'3. While ...in 'REDACTED' (in module 'REDACTED')
4. /Users/REDACTED/Build/Products/Testing-iphonesimulator/REDACTED.framework/Headers/REDACTED-Swift.h:1375:76: importing 'MyProtocol::myNavigationController'
0 swift 0x000000010e300865 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 37
1 swift 0x000000010e2ff865 llvm::sys::RunSignalHandlers() + 85
2 swift 0x000000010e300e1f SignalHandler(int) + 111
3 libsystem_platform.dylib 0x00007fff704165fd _sigtramp + 29
4 libsystem_platform.dylib 000000000000000000 _sigtramp + 18446603338632829472
5 swift 0x000000010ae70003 (anonymous namespace)::SwiftDeclConverter::VisitObjCPropertyDecl(clang::ObjCPropertyDecl const*) + 259
6 swift 0x000000010ae588db swift::ClangImporter::Implementation::importDeclAndCacheImpl(clang::NamedDecl const*, swift::importer::ImportNameVersion, bool, bool) + 1483
7 swift 0x000000010ae42972 swift::ClangImporter::loadObjCMethods(swift::ClassDecl*, swift::ObjCSelector, bool, unsigned int, llvm::TinyPtrVector<swift::AbstractFunctionDecl*>&) + 258
8 swift 0x000000010afad19d swift::ASTContext::loadObjCMethods(swift::ClassDecl*, swift::ObjCSelector, bool, unsigned int, llvm::TinyPtrVector<swift::AbstractFunctionDecl*>&) + 301
9 swift 0x000000010b17f8e4 swift::ClassDecl::lookupDirect(swift::ObjCSelector, bool) + 180
10 swift 0x000000010ad47a36 lookupObjCMethodInClass(swift::ClassDecl*, swift::ObjCSelector, bool, bool, swift::SourceManager&, bool) + 54
11 swift 0x000000010ad47440 swift::diagnoseUnintendedObjCMethodOverrides(swift::SourceFile&) + 944
12 swift 0x000000010ae290da swift::performWholeModuleTypeChecking(swift::SourceFile&) + 250
13 swift 0x0000000109fa3abd swift::CompilerInstance::performSemaUpTo(swift::SourceFile::ASTStage_t) + 8237
14 swift 0x0000000109e642fd swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 6845
15 swift 0x0000000109de8c07 main + 1255
16 libdyld.dylib 0x00007fff7021dcc9 start + 1
17 libdyld.dylib 0x0000000000000099 start + 18446603338634896337
error: Segmentation fault: 11 (in target 'REDACTEDTests' from project 'REDACTED')

@typesanitizer
Copy link

@swift-ci create

@typesanitizer
Copy link

I've edited the title to be shorter and hopefully easier to follow. I understand why you'd want to explain the whole thing, but I think a very long title is difficult to grasp. The problem description + code do provide details.

(Please feel free to re-edit the title if you think the re-wording is inaccurate.)

@beccadax
Copy link
Contributor

beccadax commented Nov 6, 2020

xy (JIRA User) I've reproduced this locally with Xcode 12's compiler, but the prepackaged version of FBSnapshotTestCase.framework in your reproducer can't be loaded by newer compilers with assertions enabled, which makes it hard to debug. Can you provide the configuration (I'm guessing a Cartfile?) needed to rebuild FBSnapshotTestCase.framework?

@swift-ci
Copy link
Collaborator Author

Comment by Romain (JIRA)

I'm external to this thread but I think brentdax (JIRA User) that you can recompile the Carthage dependencies with the workaround explained here: https://github.com/Carthage/Carthage/blob/master/Documentation/Xcode12Workaround.md

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 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
Projects
None yet
Development

No branches or pull requests

3 participants