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-13658] Crash printing @_typeEraser attribute in SourceKit CursorInfo request on View #56095

Closed
nathawes opened this issue Oct 6, 2020 · 3 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 found by stress tester Flag: An issue found by the SourceKit stress tester

Comments

@nathawes
Copy link
Collaborator

nathawes commented Oct 6, 2020

Previous ID SR-13658
Radar rdar://problem/70017224
Original Reporter @nathawes
Type Bug
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Source Tooling
Labels Bug, Crash, FoundByStressTester
Assignee None
Priority Medium

md5: 7d47f94dbc8884985634e917fac4a01c

Issue Description:

Here's a test that reproduces the issue on main:

// RUN: %empty-directory(%t)

// RUN: echo '@_typeEraser(AnyView) public protocol View {}' > %t/Module.swift
// RUN: echo 'public struct AnyView : View {' >> %t/Module.swift
// RUN: echo ' public init<T: View>(erasing: T) {}' >> %t/Module.swift
// RUN: echo '}' >> %t/Module.swift
// RUN: %swift -emit-module -o %t/Module.swiftmodule %t/Module.swift -parse-as-library

// RUN: %sourcekitd-test -req=cursor -pos=13:13 %s -- -I %t %s > %t.response

import Module

struct Foo: View {}

It seems to be from dereferencing into a null type here:
https://github.com/apple/swift/blob/main/lib/AST/Attr.cpp#L980
attr->getTypeWithoutResolving()->print(Printer, Options);

And here's the trace:

Assertion failed: (Ptr && "Cannot dereference a null Type!"), function operator->, file /Users/nhawes/github/swift/include/swift/AST/Type.h, line 220.

Thread 1 Crashed:: Dispatch queue: sourcekit.swift.ConsumeAST
0   libsystem_kernel.dylib          0x00007fff6fc5333a __pthread_kill + 10
1   libsystem_pthread.dylib         0x00007fff6fd0fe60 pthread_kill + 430
2   libsystem_c.dylib               0x00007fff6fbda8a2 __abort + 139
3   libsystem_c.dylib               0x00007fff6fbda817 abort + 135
4   libsystem_c.dylib               0x00007fff6fbd9ac6 __assert_rtn + 314
5   com.apple.SourceKitService.5.0.20200928101_osx  0x00000001043b7a63 swift::DeclAttribute::printImpl(swift::ASTPrinter&, swift::PrintOptions const&, swift::Decl const*) const (.cold.21) + 35
6   com.apple.SourceKitService.5.0.20200928101_osx  0x0000000101ad7f86 swift::DeclAttribute::printImpl(swift::ASTPrinter&, swift::PrintOptions const&, swift::Decl const*) const + 5638
7   com.apple.SourceKitService.5.0.20200928101_osx  0x0000000101ad6436 swift::DeclAttributes::print(swift::ASTPrinter&, swift::PrintOptions const&, llvm::ArrayRef<swift::DeclAttribute const*>, swift::Decl const*) + 1094
8   com.apple.SourceKitService.5.0.20200928101_osx  0x0000000101ad5fc5 swift::DeclAttributes::print(swift::ASTPrinter&, swift::PrintOptions const&, swift::Decl const*) const + 197
9   com.apple.SourceKitService.5.0.20200928101_osx  0x0000000101aaedf2 (anonymous namespace)::PrintAST::printAttributes(swift::Decl const*) + 6306
10  com.apple.SourceKitService.5.0.20200928101_osx  0x0000000101aa9627 swift::ASTVisitor<(anonymous namespace)::PrintAST, void, void, void, void, void, void>::visit(swift::Decl*) + 1559
11  com.apple.SourceKitService.5.0.20200928101_osx  0x0000000101aa53a3 (anonymous namespace)::PrintAST::visit(swift::Decl*) + 851
12  com.apple.SourceKitService.5.0.20200928101_osx  0x0000000101aa5007 swift::Decl::print(swift::ASTPrinter&, swift::PrintOptions const&) const + 119
13  com.apple.SourceKitService.5.0.20200928101_osx  0x0000000100aaeaad passCursorInfoForDecl(swift::SourceFile*, swift::ValueDecl const*, swift::ModuleDecl*, swift::Type, bool, bool, swift::ide::ResolvedCursorInfo, llvm::Optional<unsigned int>, swift::SourceLoc, llvm::ArrayRef<SourceKit::RefactoringInfo>, SourceKit::SwiftLangSupport&, swift::CompilerInvocation const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&, llvm::ArrayRef<llvm::IntrusiveRefCntPtr<SourceKit::ImmutableTextSnapshot> >, std::__1::function<void (SourceKit::RequestResult<SourceKit::CursorInfoData> const&)>) + 2253
14  com.apple.SourceKitService.5.0.20200928101_osx  0x0000000100aaccaf resolveCursor(SourceKit::SwiftLangSupport&, llvm::StringRef, unsigned int, unsigned int, bool, llvm::IntrusiveRefCntPtr<SourceKit::SwiftInvocation>, bool, bool, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>, std::__1::function<void (SourceKit::RequestResult<SourceKit::CursorInfoData> const&)>)::CursorInfoConsumer::handlePrimaryAST(llvm::IntrusiveRefCntPtr<SourceKit::ASTUnit>) + 4575
15  com.apple.SourceKitService.5.0.20200928101_osx  0x0000000100a64d2f void SourceKit::WorkQueue::DispatchData::callAndDelete<SourceKit::ASTUnit::Implementation::consumeAsync(std::__1::shared_ptr<SourceKit::SwiftASTConsumer>, llvm::IntrusiveRefCntPtr<SourceKit::ASTUnit>)::$_0>(void*) + 95
16  libdispatch.dylib               0x00007fff6fab2658 _dispatch_client_callout + 8
17  libdispatch.dylib               0x00007fff6fab7c44 _dispatch_lane_serial_drain + 597
18  libdispatch.dylib               0x00007fff6fab85d6 _dispatch_lane_invoke + 363
19  libdispatch.dylib               0x00007fff6fac1c09 _dispatch_workloop_worker_thread + 596
20  libsystem_pthread.dylib         0x00007fff6fd0ca3d _pthread_wqthread + 290
21  libsystem_pthread.dylib         0x00007fff6fd0bb77 start_wqthread + 15
@nathawes
Copy link
Collaborator Author

nathawes commented Oct 6, 2020

@swift-ci create

@nathawes
Copy link
Collaborator Author

Looks like this was fixed by #34326

@ahoppen
Copy link
Contributor

ahoppen commented Mar 18, 2021

Added a test case for this in #36488

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added the compiler The Swift compiler in itself label Dec 13, 2022
This issue was closed.
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 found by stress tester Flag: An issue found by the SourceKit stress tester
Projects
None yet
Development

No branches or pull requests

3 participants