Uploaded image for project: 'Swift'
  1. Swift
  2. SR-13658

Crash printing @_typeEraser attribute in SourceKit CursorInfo request on View

    XMLWordPrintable

    Details

      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
      

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            nathawes Nathan Hawes
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: