Skip to content

[SR-8933] Assertion failure with empty switch over uninhabited enum #51438

Closed
@mdiep

Description

@mdiep
Previous ID SR-8933
Radar rdar://problem/45216708
Original Reporter @mdiep
Type Bug
Status Resolved
Resolution Done
Environment

Swift version 4.2-dev (LLVM aeaaca98ed, Clang 35796d38ad, Swift b9d0a49)
Target: x86_64-apple-darwin18.0.0

The assertion isn't hit in Swift 4.2.

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug
Assignee @mdiep
Priority Medium

md5: 03f7cc088064e45d817420fd7c0c182e

Issue Description:

This code:

enum T4 {
    case x(Never)
}

func test4(x: T4) {
    switch x {}
}

hits in assertion:

Assertion failed: (idx < size()), function operator[], file /Users/mdiep/Repositories/apple/llvm/include/llvm/ADT/SmallVector.h, line 155.
Stack dump:
0.  Program arguments: /Users/mdiep/Repositories/apple/build/Ninja-DebugAssert/swift-macosx-x86_64/bin/swift -frontend -interpret /Users/mdiep/Repositories/apple/bugs/uninhabited.swift -enable-objc-interop -sdk /Applications/Xcode10.0.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk -color-diagnostics -module-name uninhabited 
1.  While emitting SIL for 'test4(x:)' at /Users/mdiep/Repositories/apple/bugs/uninhabited.swift:5:1
2.  While silgen emitFunction SIL function "@$s11uninhabited5test41xyAA2T4O_tF".
 for 'test4(x:)' at /Users/mdiep/Repositories/apple/bugs/uninhabited.swift:5:1
0  swift                    0x0000000113efc69c llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 60
1  swift                    0x0000000113efcc39 PrintStackTraceSignalHandler(void*) + 25
2  swift                    0x0000000113ef940e llvm::sys::RunSignalHandlers() + 990
3  swift                    0x0000000113efd885 SignalHandler(int) + 485
4  libsystem_platform.dylib 0x00007fff6838cb3d _sigtramp + 29
5  swift                    0x0000000115508568 cmark_strbuf__initbuf + 2524227
6  libsystem_c.dylib        0x00007fff6824b1c9 abort + 127
7  libsystem_c.dylib        0x00007fff68213868 basename_r + 0
8  swift                    0x000000010c5eb8d5 (anonymous namespace)::ClauseMatrix::operator[](unsigned int) + 117
9  swift                    0x000000010c5e3960 (anonymous namespace)::PatternMatchEmission::emitDispatch((anonymous namespace)::ClauseMatrix&, llvm::ArrayRef<swift::Lowering::ConsumableManagedValue>, std::__1::function<void (swift::SILLocation)> const&) + 176
10 swift                    0x000000010c5e2b0b swift::Lowering::SILGenFunction::emitSwitchStmt(swift::SwitchStmt*) + 3163
11 swift                    0x000000010c63def0 (anonymous namespace)::StmtEmitter::visitSwitchStmt(swift::SwitchStmt*) + 32
12 swift                    0x000000010c6356c4 swift::ASTVisitor<(anonymous namespace)::StmtEmitter, void, void, void, void, void, void>::visit(swift::Stmt*) + 356
13 swift                    0x000000010c638c37 (anonymous namespace)::StmtEmitter::visitBraceStmt(swift::BraceStmt*) + 951
14 swift                    0x000000010c6355bc swift::ASTVisitor<(anonymous namespace)::StmtEmitter, void, void, void, void, void, void>::visit(swift::Stmt*) + 92
15 swift                    0x000000010c635520 swift::Lowering::SILGenFunction::emitStmt(swift::Stmt*) + 48
16 swift                    0x000000010c5a0e02 swift::Lowering::SILGenFunction::emitFunction(swift::FuncDecl*) + 514
17 swift                    0x000000010c49c860 swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*)::$_1::operator()(swift::SILFunction*) const + 480
18 swift                    0x000000010c480faa void emitOrDelayFunction<swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*)::$_1>(swift::Lowering::SILGenModule&, swift::SILDeclRef, swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*)::$_1&&, bool) + 922
19 swift                    0x000000010c47f91e swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*) + 734
20 swift                    0x000000010c47f62d swift::Lowering::SILGenModule::visitFuncDecl(swift::FuncDecl*) + 29
21 swift                    0x000000010c488cc0 swift::ASTVisitor<swift::Lowering::SILGenModule, void, void, void, void, void, void>::visit(swift::Decl*) + 1072
22 swift                    0x000000010c4884fd swift::Lowering::SILGenModule::emitSourceFile(swift::SourceFile*) + 989
23 swift                    0x000000010c4895f3 swift::SILModule::constructSIL(swift::ModuleDecl*, swift::SILOptions&, swift::FileUnit*) + 1123
24 swift                    0x000000010c48a146 swift::performSILGeneration(swift::ModuleDecl*, swift::SILOptions&) + 38
25 swift                    0x000000010b22b704 generateSILModules(swift::CompilerInvocation&, swift::CompilerInstance&) + 1604
26 swift                    0x000000010b21ff2f performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 1919
27 swift                    0x000000010b21d9a7 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 5063
28 swift                    0x000000010b13e945 run_driver(llvm::StringRef, llvm::ArrayRef<char const*>) + 917
29 swift                    0x000000010b13d152 main + 3730
30 libdyld.dylib            0x00007fff681a3085 start + 1
31 libdyld.dylib            0x000000000000000a start + 2548420486

because of this logic:

    // If there are no rows remaining, then we fail.
    if (firstRow == clauses.rows()) {
      outerFailure(clauses[clauses.rows() - 1].getCasePattern());
      return;
    }

Since clauses is empty.

This code should currently give an error, but not hit an assertion.

Metadata

Metadata

Assignees

Labels

bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itself

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions