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-11683] SourceKit crashes when trying to view Swift generated interface of an Objective-C header file #54092

Open
swift-ci opened this issue Oct 30, 2019 · 6 comments
Assignees
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

@swift-ci
Copy link
Collaborator

Previous ID SR-11683
Radar rdar://problem/56701389
Original Reporter Revolt (JIRA User)
Type Bug
Environment

macOS 10.14.5 (18F132)
Xcode 11.1 (11A1027)

Additional Detail from JIRA
Votes 0
Component/s Compiler, Source Tooling
Labels Bug, ClangImporter, CompilerCrash
Assignee @beccadax
Priority Medium

md5: 13546b5062a56d81ec4f05a0f0195c6a

Issue Description:

I get this when I try to compile a project which uses Objective-C and Swift, and when I import some files (hard to tell the root cause because of nested imports) in the bridging file:

Command CompileSwift failed with a nonzero exit code
Illegal instruction: 4

@belkadan
Copy link
Contributor

Looks like that Feedback hasn't made it to us yet within Apple, but can you attach the project if you haven't already? (Even better if you can share it here.)

@swift-ci
Copy link
Collaborator Author

Comment by Iulian Onofrei (JIRA)

I couldn't initially reproduce it in a project, and I couldn't share my project either. But after more trial and error, I found out the culprit, it's caused by generics with type constraints like:

@interface BaseModel<__covariant ModelType: BaseModel *> : NSObject

Replacing it with:

@interface BaseModel<__covariant ModelType> : NSObject

fixes it.

@belkadan
Copy link
Contributor

Hm, interesting. We'd probably also need to see how you use the type to track down the crash though; if you have it reproducing in a small example that'd be very useful!

@belkadan
Copy link
Contributor

cc brentdax (JIRA User)

@beccadax
Copy link
Contributor

beccadax commented Nov 1, 2019

The radar for this is still hung up in triage where I can't modify it, but I took at peek at the attachments. This looks like a pretty straightforward stack overflow due to infinite recursion in ClangImporter:

[  1] 0x00000001084a6abd swift`::Visit() [inlined] importDecl + 12 at ImporterImpl.h:767:12
[  1] 0x00000001084a6ab1 swift`::Visit() [inlined] VisitObjCObjectPointerType + 244 at ImportType.cpp:935
[  1] 0x00000001084a69bd swift`::Visit() + 173 at TypeNodes.def:113
[  2] 0x00000001084a5845 swift`::importType() [inlined] Visit + 21 at ImportType.cpp:188:17
[  2] 0x00000001084a5830 swift`::importType() + 1408 at ImportType.cpp:1510
[  3] 0x0000000108468740 swift`::Visit() [inlined] importTypeIgnoreIUO + 26 at ImportType.cpp:1525:23
[  3] 0x0000000108468726 swift`::Visit() [inlined] importObjCGenericParams + 1645 at ImportDecl.cpp:6743
[  3] 0x00000001084680b9 swift`::Visit() [inlined] VisitObjCInterfaceDecl + 277 at ImportDecl.cpp:4547
[  3] 0x0000000108467fa4 swift`::Visit() + 10084 at DeclNodes.inc:153
[  4] 0x0000000108464e7d swift`::importDeclAndCacheImpl() [inlined] importDeclImpl + 128 at ImportDecl.cpp:7494:24
 [  5] 0x00000001084a6abd swift`::Visit() [inlined] importDecl + 12 at ImporterImpl.h:767:12

The code has moved around a little, but I think the problem might be in VisitObjCInterfaceDecl(), where we import the generic parameters before we add the declaration to the ImportedDecls map. I don't know ClangImporter very well yet, so maybe I'm missing something, but shouldn't we make sure the type is registered before we import something that might refer to it?

@swift-ci
Copy link
Collaborator Author

swift-ci commented Nov 1, 2019

Comment by Iulian Onofrei (JIRA)

I uploaded a simple project that reproduces it, let me know if you need me to upload here too.

@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
Projects
None yet
Development

No branches or pull requests

4 participants