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-12997] Unreachable hit: swift::ast_scope::ASTScopeImpl::verifyThatThisNodeComeAfterItsPriorSibling() #55442

Closed
nathawes opened this issue Jun 12, 2020 · 4 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

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

md5: 98213cb6079e4eeaf2d34df708fc4bc4

Issue Description:

Also crashes sourcekit.
Compile the below to reproduce:

func addProperties(b: Int) {
    guard true else {
      _ = "`\(b)`."

Trace:

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0   libsystem_kernel.dylib          0x00007fff6b42d33a __pthread_kill + 10
1   libsystem_pthread.dylib         0x00007fff6b4e9e60 pthread_kill + 430
2   libsystem_c.dylib               0x00007fff6b3b48a2 __abort + 139
3   libsystem_c.dylib               0x00007fff6b3b4817 abort + 135
4   swift                           0x0000000112feb04e llvm::llvm_unreachable_internal(char const*, char const*, unsigned int) + 462
5   swift                           0x000000010ea1a11f swift::ast_scope::ASTScopeImpl::verifyThatThisNodeComeAfterItsPriorSibling() const + 335
6   swift                           0x000000010ea157f9 swift::ast_scope::ASTScopeImpl* swift::ast_scope::ScopeCreator::constructExpandAndInsert<swift::ast_scope::LookupParentDiversionScope, swift::ast_scope::ASTScopeImpl*, swift::SourceLoc>(swift::ast_scope::ASTScopeImpl*, swift::ast_scope::ASTScopeImpl*, swift::SourceLoc) + 201
7   swift                           0x000000010ea05297 swift::ast_scope::GuardStmtScope::expandAScopeThatCreatesANewInsertionPoint(swift::ast_scope::ScopeCreator&) + 183
8   swift                           0x000000010ea04dd6 swift::ast_scope::ASTScopeImpl::expandAndBeCurrent(swift::ast_scope::ScopeCreator&) + 150
9   swift                           0x000000010ea04d2f swift::ExpandASTScopeRequest::evaluate(swift::Evaluator&, swift::ast_scope::ASTScopeImpl*, swift::ast_scope::ScopeCreator*) const + 15
10  swift                           0x000000010ea13fb9 llvm::Expected<swift::ExpandASTScopeRequest::OutputType> swift::Evaluator::getResultUncached<swift::ExpandASTScopeRequest>(swift::ExpandASTScopeRequest const&) + 473
11  swift                           0x000000010ea04bbe swift::ExpandASTScopeRequest::OutputType swift::evaluateOrDefault<swift::ExpandASTScopeRequest>(swift::Evaluator&, swift::ExpandASTScopeRequest, swift::ExpandASTScopeRequest::OutputType) + 94
12  swift                           0x000000010ea112fd swift::ast_scope::ASTScopeImpl* swift::ast_scope::ScopeCreator::constructExpandAndInsert<swift::ast_scope::GuardStmtScope, swift::GuardStmt*>(swift::ast_scope::ASTScopeImpl*, swift::GuardStmt*) + 173
13  swift                           0x000000010ea11203 swift::NullablePtr<swift::ast_scope::ASTScopeImpl> swift::ast_scope::ScopeCreator::ifUniqueConstructExpandAndInsert<swift::ast_scope::GuardStmtScope, swift::GuardStmt*>(swift::ast_scope::ASTScopeImpl*, swift::GuardStmt*) + 227
14  swift                           0x000000010ea0238a swift::ast_scope::ScopeCreator::addToScopeTreeAndReturnInsertionPoint(swift::ASTNode, swift::ast_scope::ASTScopeImpl*) + 122
15  swift                           0x000000010ea06496 swift::ast_scope::ScopeCreator::addSiblingsToScopeTree(swift::ast_scope::ASTScopeImpl*, swift::ast_scope::ASTScopeImpl*, llvm::ArrayRef<swift::ASTNode>) + 198
16  swift                           0x000000010ea05484 swift::ast_scope::BraceStmtScope::expandSpecifically(swift::ast_scope::ScopeCreator&) + 36
17  swift                           0x000000010ea04dd6 swift::ast_scope::ASTScopeImpl::expandAndBeCurrent(swift::ast_scope::ScopeCreator&) + 150
18  swift                           0x000000010ea04d2f swift::ExpandASTScopeRequest::evaluate(swift::Evaluator&, swift::ast_scope::ASTScopeImpl*, swift::ast_scope::ScopeCreator*) const + 15
19  swift                           0x000000010ea13fb9 llvm::Expected<swift::ExpandASTScopeRequest::OutputType> swift::Evaluator::getResultUncached<swift::ExpandASTScopeRequest>(swift::ExpandASTScopeRequest const&) + 473
20  swift                           0x000000010ea04bbe swift::ExpandASTScopeRequest::OutputType swift::evaluateOrDefault<swift::ExpandASTScopeRequest>(swift::Evaluator&, swift::ExpandASTScopeRequest, swift::ExpandASTScopeRequest::OutputType) + 94
21  swift                           0x000000010ea10edd swift::ast_scope::ASTScopeImpl* swift::ast_scope::ScopeCreator::constructExpandAndInsert<swift::ast_scope::BraceStmtScope, swift::BraceStmt*>(swift::ast_scope::ASTScopeImpl*, swift::BraceStmt*) + 173
22  swift                           0x000000010ea10de1 swift::NullablePtr<swift::ast_scope::ASTScopeImpl> swift::ast_scope::ScopeCreator::ifUniqueConstructExpandAndInsert<swift::ast_scope::BraceStmtScope, swift::BraceStmt*>(swift::ast_scope::ASTScopeImpl*, swift::BraceStmt*) + 193
23  swift                           0x000000010ea041a9 swift::ASTVisitor<swift::ast_scope::NodeAdder, swift::NullablePtr<swift::ast_scope::ASTScopeImpl>, swift::NullablePtr<swift::ast_scope::ASTScopeImpl>, swift::NullablePtr<swift::ast_scope::ASTScopeImpl>, void, void, void, swift::ast_scope::ASTScopeImpl*, swift::ast_scope::ScopeCreator&>::visit(swift::Stmt*, swift::ast_scope::ASTScopeImpl*, swift::ast_scope::ScopeCreator&) + 73
24  swift                           0x000000010ea0238a swift::ast_scope::ScopeCreator::addToScopeTreeAndReturnInsertionPoint(swift::ASTNode, swift::ast_scope::ASTScopeImpl*) + 122
25  swift                           0x000000010ea05525 swift::ast_scope::AbstractFunctionBodyScope::expandSpecifically(swift::ast_scope::ScopeCreator&) + 53
26  swift                           0x000000010ea04dd6 swift::ast_scope::ASTScopeImpl::expandAndBeCurrent(swift::ast_scope::ScopeCreator&) + 150
27  swift                           0x000000010ea04d2f swift::ExpandASTScopeRequest::evaluate(swift::Evaluator&, swift::ast_scope::ASTScopeImpl*, swift::ast_scope::ScopeCreator*) const + 15
28  swift                           0x000000010ea13fb9 llvm::Expected<swift::ExpandASTScopeRequest::OutputType> swift::Evaluator::getResultUncached<swift::ExpandASTScopeRequest>(swift::ExpandASTScopeRequest const&) + 473
29  swift                           0x000000010ea04bbe swift::ExpandASTScopeRequest::OutputType swift::evaluateOrDefault<swift::ExpandASTScopeRequest>(swift::Evaluator&, swift::ExpandASTScopeRequest, swift::ExpandASTScopeRequest::OutputType) + 94
30  swift                           0x000000010ea16dce swift::ast_scope::ASTScopeImpl::findInnermostEnclosingScope(swift::SourceLoc, swift::NullablePtr<llvm::raw_ostream>) + 62
31  swift                           0x000000010ea022ad swift::ASTScope::expandFunctionBody(swift::AbstractFunctionDecl*) + 61
32  swift                           0x000000010e7dc5a7 swift::TypeCheckFunctionBodyRequest::evaluate(swift::Evaluator&, swift::AbstractFunctionDecl*) const + 887
33  swift                           0x000000010e7e3b16 llvm::Expected<swift::TypeCheckFunctionBodyRequest::OutputType> swift::Evaluator::getResultUncached<swift::TypeCheckFunctionBodyRequest>(swift::TypeCheckFunctionBodyRequest const&) + 598
34  swift                           0x000000010e7e364c llvm::Expected<swift::TypeCheckFunctionBodyRequest::OutputType> swift::Evaluator::getResultCached<swift::TypeCheckFunctionBodyRequest, (void*)0>(swift::TypeCheckFunctionBodyRequest const&) + 316
35  swift                           0x000000010e7e34b6 llvm::Expected<swift::TypeCheckFunctionBodyRequest::OutputType> swift::Evaluator::operator()<swift::TypeCheckFunctionBodyRequest, (void*)0>(swift::TypeCheckFunctionBodyRequest const&) + 118
36  swift                           0x000000010e7dbef5 swift::TypeCheckFunctionBodyRequest::OutputType swift::evaluateOrDefault<swift::TypeCheckFunctionBodyRequest>(swift::Evaluator&, swift::TypeCheckFunctionBodyRequest, swift::TypeCheckFunctionBodyRequest::OutputType) + 37
37  swift                           0x000000010e7dbea0 swift::TypeChecker::typeCheckAbstractFunctionBody(swift::AbstractFunctionDecl*) + 64
38  swift                           0x000000010e80fd4e swift::TypeCheckSourceFileRequest::evaluate(swift::Evaluator&, swift::SourceFile*) const + 382
39  swift                           0x000000010e810a65 llvm::Expected<swift::TypeCheckSourceFileRequest::OutputType> swift::Evaluator::getResultUncached<swift::TypeCheckSourceFileRequest>(swift::TypeCheckSourceFileRequest const&) + 453
40  swift                           0x000000010e810784 llvm::Expected<swift::TypeCheckSourceFileRequest::OutputType> swift::Evaluator::getResultCached<swift::TypeCheckSourceFileRequest, (void*)0>(swift::TypeCheckSourceFileRequest const&) + 52
41  swift                           0x000000010e8106f6 llvm::Expected<swift::TypeCheckSourceFileRequest::OutputType> swift::Evaluator::operator()<swift::TypeCheckSourceFileRequest, (void*)0>(swift::TypeCheckSourceFileRequest const&) + 118
42  swift                           0x000000010e80fae0 swift::TypeCheckSourceFileRequest::OutputType swift::evaluateOrDefault<swift::TypeCheckSourceFileRequest>(swift::Evaluator&, swift::TypeCheckSourceFileRequest, swift::TypeCheckSourceFileRequest::OutputType) + 32
43  swift                           0x000000010db8078a swift::CompilerInstance::forEachFileToTypeCheck(llvm::function_ref<void (swift::SourceFile&)>) + 90
44  swift                           0x000000010db8067a swift::CompilerInstance::performSema() + 74
45  swift                           0x000000010daa2e19 performCompile(swift::CompilerInstance&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*) + 2329
46  swift                           0x000000010daa1519 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 3529
47  swift                           0x000000010da3dccd main + 861
48  libdyld.dylib                   0x00007fff6b2e5cc9 start + 1
@nathawes
Copy link
Collaborator Author

@swift-ci create

@typesanitizer
Copy link

Confirming that this reproduces on recent master @ 3455ba9 (Jun 15).

@CodaFi
Copy link
Member

CodaFi commented Jun 19, 2020

This case is explicitly called out in a40b694. I think we need to use getEndOfPreviousLoc() when we insert the missing right brace, but even that is not completely correct because that returns one-past-eof for this reproducer.

@slavapestov
Copy link
Member

I fixed this a while ago and already added a regression test.

@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. 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

5 participants