Skip to content

SILGen crash when lowering unchecked type from top-level code #83627

@jamieQ

Description

@jamieQ

Description

the attached snippet will crash during SILGen

Reproduction

let _: (Int) -> Void = { (arg: _) in
  lazy var val = arg
  _ = val
}

Stack dump

unchecked type
UNREACHABLE executed at /home/build-user/swift/include/swift/AST/TypeNodes.def:126!
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the crash backtrace.
Stack dump:
0.	Program arguments: /opt/compiler-explorer/swift-nightly/usr/bin/swift-frontend -frontend -emit-silgen -primary-file <source> -target x86_64-unknown-linux-gnu -disable-objc-interop -no-color-diagnostics -Xcc -fno-color-diagnostics -g -debug-info-format=dwarf -dwarf-version=4 -empty-abi-descriptor -enable-anonymous-context-mangled-names -file-compilation-dir /app -Xllvm --x86-asm-syntax=intel -no-auto-bridging-header-chaining -module-name output -in-process-plugin-server-path /opt/compiler-explorer/swift-nightly/usr/lib/swift/host/libSwiftInProcPluginServer.so -plugin-path /opt/compiler-explorer/swift-nightly/usr/lib/swift/host/plugins -plugin-path /opt/compiler-explorer/swift-nightly/usr/local/lib/swift/host/plugins -o /app/output.s
1.	Swift version 6.2-dev (LLVM e37aa313ae51e27, Swift 5755fb293fac0ba)
2.	Compiling with effective version 5.10
3.	While evaluating request ASTLoweringRequest(Lowering AST to SIL for file "<source>")
4.	While silgen closureexpr SIL function "@$s6outputySicfU_".
 for expression at [<source>:1:24 - line:4:1] RangeText="{ (arg: _) in
  lazy var val = arg
  _ = val
"
 #0 0x000056a99ca6bf68 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/swift-nightly/usr/bin/swift-frontend+0x8c44f68)
 #1 0x000056a99ca69a8e llvm::sys::RunSignalHandlers() (/opt/compiler-explorer/swift-nightly/usr/bin/swift-frontend+0x8c42a8e)
 #2 0x000056a99ca6c601 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
 #3 0x00007552b7042520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x00007552b70969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #5 0x00007552b7042476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #6 0x00007552b70287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #7 0x000056a99c9bf970 llvm::install_out_of_memory_new_handler() (/opt/compiler-explorer/swift-nightly/usr/bin/swift-frontend+0x8b98970)
 #8 0x000056a995a57bb7 swift::CanTypeVisitor<swift::Lowering::TypeConverter::computeLoweredRValueType(swift::TypeExpansionContext, swift::Lowering::AbstractionPattern, swift::CanType)::LoweredRValueTypeVisitor, swift::CanType>::visit(swift::CanType) TypeLowering.cpp:0:0
 #9 0x000056a995a545d9 swift::Lowering::TypeConverter::getTypeLowering(swift::Lowering::AbstractionPattern, swift::Type, swift::TypeExpansionContext) (/opt/compiler-explorer/swift-nightly/usr/bin/swift-frontend+0x1c2d5d9)
#10 0x000056a995a6fced swift::Lowering::TypeConverter::computeLoweredRValueType(swift::TypeExpansionContext, swift::Lowering::AbstractionPattern, swift::CanType)::LoweredRValueTypeVisitor::visitType(swift::CanType) TypeLowering.cpp:0:0
#11 0x000056a995a545d9 swift::Lowering::TypeConverter::getTypeLowering(swift::Lowering::AbstractionPattern, swift::Type, swift::TypeExpansionContext) (/opt/compiler-explorer/swift-nightly/usr/bin/swift-frontend+0x1c2d5d9)
#12 0x000056a9952d8db7 swift::Lowering::TypeConverter::getLoweredRValueType(swift::TypeExpansionContext, swift::Type) crtstuff.c:0:0
#13 0x000056a9955ea004 swift::Lowering::SILGenFunction::emitLocalVariableWithCleanup(swift::VarDecl*, std::optional<swift::MarkUninitializedInst::Kind>, unsigned int, bool) crtstuff.c:0:0
#14 0x000056a9955e94a3 swift::Lowering::SILGenFunction::emitInitializationForVarDecl(swift::VarDecl*, bool, bool) crtstuff.c:0:0
#15 0x000056a9955eaaae swift::Lowering::SILGenFunction::emitPatternBinding(swift::PatternBindingDecl*, unsigned int, bool) crtstuff.c:0:0
#16 0x000056a9955f4332 void llvm::function_ref<void (swift::VarDecl*)>::callback_fn<swift::Lowering::SILGenFunction::visitVarDecl(swift::VarDecl*)::$_3>(long, swift::VarDecl*) SILGenDecl.cpp:0:0
#17 0x000056a996ae7deb swift::VarDecl::visitAuxiliaryDecls(llvm::function_ref<void (swift::VarDecl*)>) const (/opt/compiler-explorer/swift-nightly/usr/bin/swift-frontend+0x2cc0deb)
#18 0x000056a9955eb40e swift::Lowering::SILGenFunction::visitVarDecl(swift::VarDecl*) crtstuff.c:0:0
#19 0x000056a9956c4901 swift::ASTVisitor<(anonymous namespace)::StmtEmitter, void, void, void, void, void, void>::visit(swift::Stmt*) SILGenStmt.cpp:0:0
#20 0x000056a9956c30bd swift::Lowering::SILGenFunction::emitStmt(swift::Stmt*) crtstuff.c:0:0
#21 0x000056a99563c0fc swift::Lowering::SILGenFunction::emitClosure(swift::AbstractClosureExpr*) crtstuff.c:0:0
#22 0x000056a9955a97ee swift::Lowering::SILGenModule::emitFunctionDefinition(swift::SILDeclRef, swift::SILFunction*) crtstuff.c:0:0
#23 0x000056a9955b3a26 void llvm::function_ref<void ()>::callback_fn<swift::Lowering::SILGenModule::emitClosure(swift::AbstractClosureExpr*, swift::Lowering::FunctionTypeInfo const&)::$_4>(long) SILGen.cpp:0:0
#24 0x000056a995a5d90e swift::Lowering::TypeConverter::withClosureTypeInfo(swift::AbstractClosureExpr*, swift::Lowering::FunctionTypeInfo const&, llvm::function_ref<void ()>) (/opt/compiler-explorer/swift-nightly/usr/bin/swift-frontend+0x1c3690e)
#25 0x000056a9955ad2f5 swift::Lowering::SILGenModule::emitClosure(swift::AbstractClosureExpr*, swift::Lowering::FunctionTypeInfo const&) crtstuff.c:0:0
#26 0x000056a99562e5e0 (anonymous namespace)::RValueEmitter::emitClosureReference(swift::AbstractClosureExpr*, swift::Lowering::FunctionTypeInfo const&) SILGenExpr.cpp:0:0
#27 0x000056a99562e35f (anonymous namespace)::RValueEmitter::visitAbstractClosureExpr(swift::AbstractClosureExpr*, swift::Lowering::SGFContext) SILGenExpr.cpp:0:0
#28 0x000056a99561573b swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) SILGenExpr.cpp:0:0
#29 0x000056a995604fa5 swift::Lowering::SILGenFunction::emitExprInto(swift::Expr*, swift::Lowering::Initialization*, std::optional<swift::SILLocation>) crtstuff.c:0:0
#30 0x000056a9955eaf7f swift::Lowering::SILGenFunction::emitPatternBinding(swift::PatternBindingDecl*, unsigned int, bool) crtstuff.c:0:0
#31 0x000056a9955f43d2 swift::ASTVisitor<swift::Lowering::SILGenFunction, void, void, void, void, void, void>::visit(swift::Decl*) crtstuff.c:0:0
#32 0x000056a9956d716c swift::Lowering::SILGenTopLevel::visitTopLevelCodeDecl(swift::TopLevelCodeDecl*) (/opt/compiler-explorer/swift-nightly/usr/bin/swift-frontend+0x18b016c)
#33 0x000056a9956d4fdb swift::Lowering::SILGenTopLevel::visitSourceFile(swift::SourceFile*) (/opt/compiler-explorer/swift-nightly/usr/bin/swift-frontend+0x18adfdb)
#34 0x000056a9956d4260 swift::Lowering::SILGenModule::emitEntryPoint(swift::SourceFile*, swift::SILFunction*) crtstuff.c:0:0
#35 0x000056a9956d6725 swift::Lowering::SILGenModule::emitEntryPoint(swift::SourceFile*) crtstuff.c:0:0
#36 0x000056a9955af013 swift::Lowering::SILGenModule::emitSourceFile(swift::SourceFile*) crtstuff.c:0:0
#37 0x000056a9955af7d4 swift::ASTLoweringRequest::evaluate(swift::Evaluator&, swift::ASTLoweringDescriptor) const (/opt/compiler-explorer/swift-nightly/usr/bin/swift-frontend+0x17887d4)
#38 0x000056a9956c29b6 swift::SimpleRequest<swift::ASTLoweringRequest, std::unique_ptr<swift::SILModule, std::default_delete<swift::SILModule>> (swift::ASTLoweringDescriptor), (swift::RequestFlags)17>::evaluateRequest(swift::ASTLoweringRequest const&, swift::Evaluator&) crtstuff.c:0:0
#39 0x000056a9955b4863 swift::ASTLoweringRequest::OutputType swift::Evaluator::getResultUncached<swift::ASTLoweringRequest, swift::ASTLoweringRequest::OutputType swift::evaluateOrFatal<swift::ASTLoweringRequest>(swift::Evaluator&, swift::ASTLoweringRequest)::'lambda'()>(swift::ASTLoweringRequest const&, swift::ASTLoweringRequest::OutputType swift::evaluateOrFatal<swift::ASTLoweringRequest>(swift::Evaluator&, swift::ASTLoweringRequest)::'lambda'()) crtstuff.c:0:0
#40 0x000056a9955b018f swift::performASTLowering(swift::FileUnit&, swift::Lowering::TypeConverter&, swift::SILOptions const&, swift::IRGenOptions const*) (/opt/compiler-explorer/swift-nightly/usr/bin/swift-frontend+0x178918f)
#41 0x000056a994d763cf swift::performCompileStepsPostSema(swift::CompilerInstance&, int&, swift::FrontendObserver*) (/opt/compiler-explorer/swift-nightly/usr/bin/swift-frontend+0xf4f3cf)
#42 0x000056a994d8c65a withSemanticAnalysis(swift::CompilerInstance&, swift::FrontendObserver*, llvm::function_ref<bool (swift::CompilerInstance&)>, bool) FrontendTool.cpp:0:0
#43 0x000056a994d7b704 performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) FrontendTool.cpp:0:0
#44 0x000056a994d78661 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) (/opt/compiler-explorer/swift-nightly/usr/bin/swift-frontend+0xf51661)
#45 0x000056a994af4d35 swift::mainEntry(int, char const**) (/opt/compiler-explorer/swift-nightly/usr/bin/swift-frontend+0xccdd35)
#46 0x00007552b7029d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#47 0x00007552b7029e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#48 0x000056a994af3355 _start (/opt/compiler-explorer/swift-nightly/usr/bin/swift-frontend+0xccc355)

*** Signal 6: Backtracing from 0x7552b711e88d... done ***

*** Program crashed: Aborted at 0x0000280000000001 ***

Platform: x86_64 Linux (Ubuntu 22.04.5 LTS)

Thread 0 "swift-frontend" crashed:

  0  0x00007552b711e88d <unknown> in libc.so.6
...


Registers:

rax 0x0000000000000000  0
rdx 0x0000000000000006  6
rcx 0x00007552b711e88d  48 3d 01 f0 ff ff 73 01 c3 48 8b 0d 73 b5 0f 00  H=·ðÿÿs·ÃH··sµ··
rbx 0x0000000000000006  6
rsi 0x0000000000000001  1
rdi 0x0000000000000001  1
rbp 0x0000000000000001  1
rsp 0x000056a9ceee4368  2b c6 a6 9c a9 56 00 00 f0 45 ee ce a9 56 00 00  +Ʀ·©V··ðEîΩV··
 r8 0x000056a9ceee45f0  06 00 00 00 00 00 00 00 fa ff ff ff 00 00 00 00  ········úÿÿÿ····
 r9 0x000056a9ceee45f0  06 00 00 00 00 00 00 00 fa ff ff ff 00 00 00 00  ········úÿÿÿ····
r10 0x000056a9ceee45f0  06 00 00 00 00 00 00 00 fa ff ff ff 00 00 00 00  ········úÿÿÿ····
r11 0x0000000000000246  582
r12 0x0000000000000000  0
r13 0x0000000000000000  0
r14 0x0000000000000000  0
r15 0x000056a9ceee4378  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ················
rip 0x00007552b711e88d  48 3d 01 f0 ff ff 73 01 c3 48 8b 0d 73 b5 0f 00  H=·ðÿÿs·ÃH··sµ··

rflags 0x0000000000000246  ZF PF

cs 0x0033  fs 0x0000  gs 0x0000


Images (26 omitted):

0x00007552b7000000–0x00007552b71bc341 cd410b710f0f094c6832edd95931006d883af48e libc.so.6 /lib/x86_64-linux-gnu/libc.so.6

Backtrace took 0.02s

Program terminated with signal: SIGSEGV
Compiler returned: 139

Expected behavior

no crash

Environment

Swift version 6.2-dev (LLVM e37aa313ae51e27, Swift 5755fb2)
Target: x86_64-unknown-linux-gnu

Additional information

godbolt: https://swift.godbolt.org/z/3a41P9rP5

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.closuresFeature: closurescompilerThe Swift compiler itselfcrashBug: A crash, i.e., an abnormal termination of softwarelazy varFeature: Lazy variablestype checkerArea → compiler: Semantic analysis

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions