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-12283] SourceKit's CursorInfo request fails when invoked on the string value of an enum element decl. #54711

Closed
nathawes opened this issue Feb 27, 2020 · 3 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. found by stress tester Flag: An issue found by the SourceKit stress tester

Comments

@nathawes
Copy link
Collaborator

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

md5: cd155286f09891d9423a606b2a73fc4a

Issue Description:

Reproducer:

enum Chord: String {
    case email = /*Invoke on this string ->*/"foo"
}
$ sourcekitd-test -req=cursor -cursor-action -pos=2:46 /tmp/test.swift -- /tmp/test.swift
Assertion failed: (Val && "isa<> used on a null pointer")

Thread 3 Crashed:: Dispatch queue: sourcekit.swift.ConsumeAST
0   libsystem_kernel.dylib          0x00007fff66f777fa __pthread_kill + 10
1   libsystem_pthread.dylib         0x00007fff67034bc1 pthread_kill + 432
2   libsystem_c.dylib               0x00007fff66efeab6 __abort + 139
3   libsystem_c.dylib               0x00007fff66efea2b abort + 135
4   libsystem_c.dylib               0x00007fff66efdcd6 __assert_rtn + 314
5   com.apple.SourceKitService._osx 0x000000010347ca27 llvm::isa_impl_cl<swift::LiteralExpr, swift::Expr const*>::doit(swift::Expr const*) + 87 (Casting.h:105)
6   com.apple.SourceKitService._osx 0x000000010347c9b8 llvm::isa_impl_wrap<swift::LiteralExpr, swift::Expr const*, swift::Expr const*>::doit(swift::Expr const* const&) + 24 (Casting.h:132)
7   com.apple.SourceKitService._osx 0x000000010347c992 llvm::isa_impl_wrap<swift::LiteralExpr, swift::Expr* const, swift::Expr const*>::doit(swift::Expr* const&) + 34 (Casting.h:122)
8   com.apple.SourceKitService._osx 0x0000000103470235 bool llvm::isa<swift::LiteralExpr, swift::Expr*>(swift::Expr* const&) + 21 (Casting.h:142)
9   com.apple.SourceKitService._osx 0x0000000103beba75 llvm::cast_retty<swift::LiteralExpr, swift::Expr*>::ret_type llvm::dyn_cast<swift::LiteralExpr, swift::Expr>(swift::Expr*) + 21 (Casting.h:343)
10  com.apple.SourceKitService._osx 0x0000000103bea222 (anonymous namespace)::Traversal::visitEnumElementDecl(swift::EnumElementDecl*) + 114 (ASTWalker.cpp:408)
11  com.apple.SourceKitService._osx 0x0000000103be972d swift::ASTVisitor<(anonymous namespace)::Traversal, swift::Expr*, swift::Stmt*, bool, swift::Pattern*, bool, void>::visit(swift::Decl*) + 1469 (DeclNodes.def:175)
12  com.apple.SourceKitService._osx 0x0000000103be90d8 (anonymous namespace)::Traversal::visit(swift::Decl*) + 56 (ASTWalker.cpp:114)
13  com.apple.SourceKitService._osx 0x0000000103bdf76c (anonymous namespace)::Traversal::doIt(swift::Decl*) + 108 (ASTWalker.cpp:1234)
14  com.apple.SourceKitService._osx 0x0000000103beadc1 (anonymous namespace)::Traversal::visitNominalTypeDecl(swift::NominalTypeDecl*) + 817 (ASTWalker.cpp:293)
15  com.apple.SourceKitService._osx 0x0000000103be9a53 swift::ASTVisitor<(anonymous namespace)::Traversal, swift::Expr*, swift::Stmt*, bool, swift::Pattern*, bool, void>::visitEnumDecl(swift::EnumDecl*) + 35 (DeclNodes.def:150)
16  com.apple.SourceKitService._osx 0x0000000103be9203 swift::ASTVisitor<(anonymous namespace)::Traversal, swift::Expr*, swift::Stmt*, bool, swift::Pattern*, bool, void>::visit(swift::Decl*) + 147 (DeclNodes.def:150)
17  com.apple.SourceKitService._osx 0x0000000103be90d8 (anonymous namespace)::Traversal::visit(swift::Decl*) + 56 (ASTWalker.cpp:114)
18  com.apple.SourceKitService._osx 0x0000000103bdf76c (anonymous namespace)::Traversal::doIt(swift::Decl*) + 108 (ASTWalker.cpp:1234)
19  com.apple.SourceKitService._osx 0x0000000103bdf6f5 swift::Decl::walk(swift::ASTWalker&) + 53 (ASTWalker.cpp:1896)
20  com.apple.SourceKitService._osx 0x0000000103f3c7e1 swift::SourceFile::walk(swift::ASTWalker&) + 209 (Module.cpp:1750)
21  com.apple.SourceKitService._osx 0x0000000101f2cf50 swift::SourceEntityWalker::walk(swift::SourceFile&) + 80 (SourceEntityWalker.cpp:725)
22  com.apple.SourceKitService._osx 0x0000000101f3ecd6 CursorInfoResolver::resolve(swift::SourceLoc) + 134 (IDERequests.cpp:159)
23  com.apple.SourceKitService._osx 0x0000000101f3fbed swift::CursorInfoRequest::evaluate(swift::Evaluator&, swift::CursorInfoOwner) const + 189 (IDERequests.cpp:311)
24  com.apple.SourceKitService._osx 0x0000000101f42f18 llvm::Expected<swift::ide::ResolvedCursorInfo> swift::SimpleRequest<swift::CursorInfoRequest, swift::ide::ResolvedCursorInfo (swift::CursorInfoOwner), (swift::CacheKind)1>::callDerived<0ul>(swift::Evaluator&, llvm::index_sequence<0ul>) const + 104 (SimpleRequest.h:200)
25  com.apple.SourceKitService._osx 0x0000000101f42d27 swift::SimpleRequest<swift::CursorInfoRequest, swift::ide::ResolvedCursorInfo (swift::CursorInfoOwner), (swift::CacheKind)1>::evaluateRequest(swift::CursorInfoRequest const&, swift::Evaluator&) + 39 (SimpleRequest.h:219)
26  com.apple.SourceKitService._osx 0x0000000101b106cb llvm::Expected<swift::CursorInfoRequest::OutputType> swift::Evaluator::getResultUncached<swift::CursorInfoRequest>(swift::CursorInfoRequest const&) + 395 (Evaluator.h:379)
27  com.apple.SourceKitService._osx 0x0000000101b10449 llvm::Expected<swift::CursorInfoRequest::OutputType> swift::Evaluator::getResultCached<swift::CursorInfoRequest, (void*)0>(swift::CursorInfoRequest const&) + 265 (Evaluator.h:420)
28  com.apple.SourceKitService._osx 0x0000000101b1016d llvm::Expected<swift::CursorInfoRequest::OutputType> swift::Evaluator::operator()<swift::CursorInfoRequest, (void*)0>(swift::CursorInfoRequest const&) + 77 (Evaluator.h:271)
29  com.apple.SourceKitService._osx 0x0000000101b0c9d1 swift::CursorInfoRequest::OutputType swift::evaluateOrDefault<swift::CursorInfoRequest>(swift::Evaluator&, swift::CursorInfoRequest, swift::CursorInfoRequest::OutputType) + 97 (Evaluator.h:105)
30  com.apple.SourceKitService._osx 0x0000000101b07426 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>) + 1558 (SwiftSourceDocInfo.cpp:1332)
31  com.apple.SourceKitService._osx 0x0000000101a0f9b8 SourceKit::ASTUnit::Implementation::consumeAsync(std::__1::shared_ptr<SourceKit::SwiftASTConsumer>, llvm::IntrusiveRefCntPtr<SourceKit::ASTUnit>)::$_0::operator()() const + 120 (SwiftASTManager.cpp:209)
32  com.apple.SourceKitService._osx 0x0000000101a0f90d void SourceKit::WorkQueue::DispatchData::callAndDelete<SourceKit::ASTUnit::Implementation::consumeAsync(std::__1::shared_ptr<SourceKit::SwiftASTConsumer>, llvm::IntrusiveRefCntPtr<SourceKit::ASTUnit>)::$_0>(void*) + 29 (Concurrency.h:213)
33  libdispatch.dylib               0x00007fff66dd750e _dispatch_client_callout + 8
34  libdispatch.dylib               0x00007fff66ddcace _dispatch_lane_serial_drain + 597
35  libdispatch.dylib               0x00007fff66ddd452 _dispatch_lane_invoke + 363
36  libdispatch.dylib               0x00007fff66de6a9e _dispatch_workloop_worker_thread + 598
37  libsystem_pthread.dylib         0x00007fff670316fc _pthread_wqthread + 290
38  libsystem_pthread.dylib         0x00007fff67030827 start_wqthread + 15
@nathawes
Copy link
Collaborator Author

@swift-ci create

@nathawes
Copy link
Collaborator Author

Looks like the visitor isn't checking if doIt() returns null (indicating traversal should abort) when walking EnumElementDecls:

bool visitEnumElementDecl(EnumElementDecl *ED) {
    if (auto *PL = ED->getParameterList()) {
      visit(PL);
    }

    if (auto *rawLiteralExpr = ED->getRawValueUnchecked()) {
      Expr *newRawExpr = doIt(rawLiteralExpr);
      if (auto newRawLiteralExpr = dyn_cast<LiteralExpr>(newRawExpr))
        ED->setRawValueExpr(newRawLiteralExpr);
      else
        return true;
    }
    return false;
  }

@benlangmuir
Copy link
Member

Should be fixed by #30162

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 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. found by stress tester Flag: An issue found by the SourceKit stress tester
Projects
None yet
Development

No branches or pull requests

2 participants