Skip to content

Assigning to self in a Never initializer using a switch expression crashes the compiler #66490

Closed
@hamishknight

Description

@hamishknight

This crashes in SILGen:

extension Never {
  init(value: Self) {
    self = switch value {
    case let v: v
    }
  }
}
Assertion failed: (hasValidInsertionPoint()), function insertImpl, file SILBuilder.h, line 2953.
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the crash backtrace.
Stack dump:
0.	Program arguments: ./swift -frontend -emit-ir /Users/hamish/src/swift-test-arena/swift-test-arena/main.swift -sdk /Users/hamish/src/MacOSX.sdk/ -debug-diagnostic-names
1.	Swift version 5.9-dev (LLVM ca18bb83c79530c, Swift 40396d681d52ebd)
2.	Compiling with the current language version
3.	While evaluating request ASTLoweringRequest(Lowering AST to SIL for module main)
4.	While silgen emitValueConstructor SIL function "@$ss5NeverO4mainE5valueA2B_tcfC".
 for 'init(value:)' (at /Users/hamish/src/swift-test-arena/swift-test-arena/main.swift:2324:3)
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
0  swift-frontend           0x0000000106d1c767 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 39
1  swift-frontend           0x0000000106d1b6b8 llvm::sys::RunSignalHandlers() + 248
2  swift-frontend           0x0000000106d1cdb0 SignalHandler(int) + 272
3  libsystem_platform.dylib 0x00007ff808ba65ed _sigtramp + 29
4  libsystem_platform.dylib 0x00007ff1b316d290 _sigtramp + 18446744046502964416
5  libsystem_c.dylib        0x00007ff808a9fb45 abort + 123
6  libsystem_c.dylib        0x00007ff808a9ee5e err + 0
7  swift-frontend           0x0000000106d22b83 swift::SILBuilder::insertImpl(swift::SILInstruction*) (.cold.1) + 35
8  swift-frontend           0x00000001011b3f7d swift::SILBuilder::insertImpl(swift::SILInstruction*) + 141
9  swift-frontend           0x0000000101cfde93 swift::SILBuilder::createLoad(swift::SILLocation, swift::SILValue, swift::LoadOwnershipQualifier) + 227
10 swift-frontend           0x000000010198196a swift::Lowering::SILGenBuilder::createLoadBorrow(swift::SILLocation, swift::Lowering::ManagedValue) + 74
11 swift-frontend           0x0000000101938859 (anonymous namespace)::ExplodeTupleValue::visitType(swift::CanType, swift::Lowering::ManagedValue) + 121
12 swift-frontend           0x00000001019365b7 swift::Lowering::RValue::RValue(swift::Lowering::SILGenFunction&, swift::Expr*, swift::Lowering::ManagedValue) + 183
13 swift-frontend           0x00000001019cf1cf (anonymous namespace)::RValueEmitter::visitSingleValueStmtExpr(swift::SingleValueStmtExpr*, swift::Lowering::SGFContext) + 671
14 swift-frontend           0x00000001019be05f swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 1231
15 swift-frontend           0x00000001019b1838 swift::Lowering::SILGenFunction::emitRValue(swift::Expr*, swift::Lowering::SGFContext) + 40
16 swift-frontend           0x000000010192a683 swift::Lowering::ArgumentSource::getAsRValue(swift::Lowering::SILGenFunction&, swift::Lowering::SGFContext) && + 115
17 swift-frontend           0x00000001019f5d67 swift::Lowering::SILGenFunction::emitAssignToLValue(swift::SILLocation, swift::Lowering::ArgumentSource&&, swift::Lowering::LValue&&) + 359
18 swift-frontend           0x00000001019cdcd2 (anonymous namespace)::RValueEmitter::visitAssignExpr(swift::AssignExpr*, swift::Lowering::SGFContext) + 1250
19 swift-frontend           0x00000001019be02e swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 1182
20 swift-frontend           0x00000001019b475c swift::Lowering::SILGenFunction::emitIgnoredExpr(swift::Expr*) + 1116
21 swift-frontend           0x0000000101a3a209 swift::ASTVisitor<(anonymous namespace)::StmtEmitter, void, void, void, void, void, void>::visit(swift::Stmt*) + 5001
22 swift-frontend           0x0000000101a38e75 swift::Lowering::SILGenFunction::emitStmt(swift::Stmt*) + 21
23 swift-frontend           0x000000010198f705 swift::Lowering::SILGenFunction::emitValueConstructor(swift::ConstructorDecl*) + 8661
24 swift-frontend           0x0000000101943cf9 swift::Lowering::SILGenModule::emitFunctionDefinition(swift::SILDeclRef, swift::SILFunction*) + 6473
25 swift-frontend           0x0000000101945bd7 emitOrDelayFunction(swift::Lowering::SILGenModule&, swift::SILDeclRef) + 231
26 swift-frontend           0x0000000101945f12 swift::Lowering::SILGenModule::emitConstructor(swift::ConstructorDecl*) + 338
27 swift-frontend           0x0000000101a4b389 swift::ASTVisitor<SILGenExtension, void, void, void, void, void, void>::visit(swift::Decl*) + 169
28 swift-frontend           0x0000000101a47325 SILGenExtension::emitExtension(swift::ExtensionDecl*) + 101
29 swift-frontend           0x0000000101a472b5 swift::Lowering::SILGenModule::visitExtensionDecl(swift::ExtensionDecl*) + 21
30 swift-frontend           0x00000001019483f5 swift::ASTLoweringRequest::evaluate(swift::Evaluator&, swift::ASTLoweringDescriptor) const + 2341
31 swift-frontend           0x0000000101a38968 swift::SimpleRequest<swift::ASTLoweringRequest, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule>> (swift::ASTLoweringDescriptor), (swift::RequestFlags)9>::evaluateRequest(swift::ASTLoweringRequest const&, swift::Evaluator&) + 120
32 swift-frontend           0x000000010194bff2 llvm::Expected<swift::ASTLoweringRequest::OutputType> swift::Evaluator::getResultUncached<swift::ASTLoweringRequest>(swift::ASTLoweringRequest const&) + 386
33 swift-frontend           0x00000001019498a1 swift::performASTLowering(swift::ModuleDecl*, swift::Lowering::TypeConverter&, swift::SILOptions const&, swift::IRGenOptions const*) + 161
34 swift-frontend           0x00000001013811c2 swift::performCompileStepsPostSema(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 2290
35 swift-frontend           0x00000001013921d0 withSemanticAnalysis(swift::CompilerInstance&, swift::FrontendObserver*, llvm::function_ref<bool (swift::CompilerInstance&)>, bool) + 144
36 swift-frontend           0x00000001013836cd performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 861
37 swift-frontend           0x0000000101382578 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 2872
38 swift-frontend           0x000000010119dd75 swift::mainEntry(int, char const**) + 2309
39 dyld                     0x00007ff80881f41f start + 1903

rdar://110636210

Metadata

Metadata

Assignees

Labels

SILGenArea → compiler: The SIL generation stageassertion failureBug → crash: An assertion failurebugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfcrashBug: A crash, i.e., an abnormal termination of softwareexpressionsFeature: expressionsswift 5.9switchFeature → statements: 'switch' statements

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions