Skip to content

Compiler crash around non-copyables: no address for captured var #83220

@MahdiBM

Description

@MahdiBM

Description

Just bumped into this crash randomly. It probably helps the crash that the related type is non-copyable. The code I wrote there isn't even logically correct, but well the compiler doesn't care about that 😅
See repro/stack-dump.

Reproduction

docker run --rm -it swiftlang/swift:nightly-6.2-noble bash -c '                                                                                                                                                                                                                                        
  git clone https://github.com/MahdiBM/swift-dns
  cd swift-dns
  git checkout swift-bug
  swift build
'

Stack dump

Building for debugging...
error: compile command failed due to signal 6 (use -v to see invocation)
swift-frontend: /home/build-user/swift/lib/SILGen/SILGenFunction.cpp:944: void swift::Lowering::SILGenFunction::emitCaptures(SILLocation, SILDeclRef, CaptureEmission, SmallVectorImpl<ManagedValue> &): Assertion `val->getType().isAddress() && "no address for captured var!"' failed.
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the crash backtrace.
Stack dump:
0.	Program arguments: /usr/bin/swift-frontend -frontend -c /swift-dns/Sources/DNSClient/+Logger.swift /swift-dns/Sources/DNSClient/ChannelHandlers/AddressedEnvelopeInboundChannelHandler.swift /swift-dns/Sources/DNSClient/ChannelHandlers/AddressedEnvelopeOutboundChannelHandler.swift /swift-dns/Sources/DNSClient/ChannelHandlers/DNSChannelHandler+StateMachine.swift /swift-dns/Sources/DNSClient/ChannelHandlers/DNSChannelHandler.swift /swift-dns/Sources/DNSClient/ChannelHandlers/DNSMessageDecoder.swift /swift-dns/Sources/DNSClient/Connection/DNSConnection+ConnectionPool.swift /swift-dns/Sources/DNSClient/Connection/DNSConnection.swift /swift-dns/Sources/DNSClient/Connection/DNSConnectionConfiguration.swift /swift-dns/Sources/DNSClient/Connection/IDGenerator.swift /swift-dns/Sources/DNSClient/Connection/NonCopyableIDGenerator.swift /swift-dns/Sources/DNSClient/ConnectionFactory.swift /swift-dns/Sources/DNSClient/DNSClient+query.swift /swift-dns/Sources/DNSClient/DNSClient.swift /swift-dns/Sources/DNSClient/DNSClientConfiguration.swift /swift-dns/Sources/DNSClient/DNSClientError.swift /swift-dns/Sources/DNSClient/DNSClientMetrics.swift /swift-dns/Sources/DNSClient/DNSServerAddress.swift -primary-file /swift-dns/Sources/DNSClient/MessageIDGenerator.swift -primary-file /swift-dns/Sources/DNSClient/PendingQuery.swift /swift-dns/Sources/DNSClient/QueryPool.swift /swift-dns/Sources/DNSClient/exports.swift -emit-dependencies-path /swift-dns/.build/aarch64-unknown-linux-gnu/debug/DNSClient.build/MessageIDGenerator.d -emit-reference-dependencies-path /swift-dns/.build/aarch64-unknown-linux-gnu/debug/DNSClient.build/MessageIDGenerator.swiftdeps -serialize-diagnostics-path /swift-dns/.build/aarch64-unknown-linux-gnu/debug/DNSClient.build/MessageIDGenerator.dia -emit-dependencies-path /swift-dns/.build/aarch64-unknown-linux-gnu/debug/DNSClient.build/PendingQuery.d -emit-reference-dependencies-path /swift-dns/.build/aarch64-unknown-linux-gnu/debug/DNSClient.build/PendingQuery.swiftdeps -serialize-diagnostics-path /swift-dns/.build/aarch64-unknown-linux-gnu/debug/DNSClient.build/PendingQuery.dia -target aarch64-unknown-linux-gnu -Xllvm -aarch64-use-tbi -disable-objc-interop -I /swift-dns/.build/aarch64-unknown-linux-gnu/debug/Modules -color-diagnostics -Xcc -fcolor-diagnostics -enable-testing -g -debug-info-format=dwarf -dwarf-version=4 -module-cache-path /swift-dns/.build/aarch64-unknown-linux-gnu/debug/ModuleCache -swift-version 6 -Onone -D SWIFT_PACKAGE -D DEBUG -D SWIFT_MODULE_RESOURCE_BUNDLE_UNAVAILABLE -D ServiceLifecycleSupport -enable-upcoming-feature MemberImportVisibility -enable-upcoming-feature InternalImportsByDefault -enable-upcoming-feature ExistentialAny -enable-upcoming-feature StrictMemorySafety -enable-experimental-feature "AvailabilityMacro=swiftDNS 1.0:macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0" -empty-abi-descriptor -enable-anonymous-context-mangled-names -file-compilation-dir /swift-dns -Xcc -fmodule-map-file=/swift-dns/.build/aarch64-unknown-linux-gnu/debug/CSwiftDNSIDNA.build/module.modulemap -Xcc -I -Xcc /swift-dns/Sources/CSwiftDNSIDNA/include -Xcc -fmodule-map-file=/swift-dns/.build/checkouts/swift-atomics/Sources/_AtomicsShims/include/module.modulemap -Xcc -I -Xcc /swift-dns/.build/checkouts/swift-atomics/Sources/_AtomicsShims/include -Xcc -fmodule-map-file=/swift-dns/.build/aarch64-unknown-linux-gnu/debug/CNIOWASI.build/module.modulemap -Xcc -I -Xcc /swift-dns/.build/checkouts/swift-nio/Sources/CNIOWASI/include -Xcc -fmodule-map-file=/swift-dns/.build/checkouts/swift-nio/Sources/CNIOWindows/include/module.modulemap -Xcc -I -Xcc /swift-dns/.build/checkouts/swift-nio/Sources/CNIOWindows/include -Xcc -fmodule-map-file=/swift-dns/.build/aarch64-unknown-linux-gnu/debug/CNIOLinux.build/module.modulemap -Xcc -I -Xcc /swift-dns/.build/checkouts/swift-nio/Sources/CNIOLinux/include -Xcc -fmodule-map-file=/swift-dns/.build/aarch64-unknown-linux-gnu/debug/CNIODarwin.build/module.modulemap -Xcc -I -Xcc /swift-dns/.build/checkouts/swift-nio/Sources/CNIODarwin/include -Xcc -fmodule-map-file=/swift-dns/.build/aarch64-unknown-linux-gnu/debug/CNIOAtomics.build/module.modulemap -Xcc -I -Xcc /swift-dns/.build/checkouts/swift-nio/Sources/CNIOAtomics/include -Xcc -fmodule-map-file=/swift-dns/.build/aarch64-unknown-linux-gnu/debug/CNIOBoringSSLShims.build/module.modulemap -Xcc -I -Xcc /swift-dns/.build/checkouts/swift-nio-ssl/Sources/CNIOBoringSSLShims/include -Xcc -fmodule-map-file=/swift-dns/.build/checkouts/swift-nio-ssl/Sources/CNIOBoringSSL/include/module.modulemap -Xcc -I -Xcc /swift-dns/.build/checkouts/swift-nio-ssl/Sources/CNIOBoringSSL/include -Xcc -fPIC -Xcc -g -Xcc -fno-omit-frame-pointer -no-auto-bridging-header-chaining -module-name DNSClient -package-name swift_dns -in-process-plugin-server-path /usr/lib/swift/host/libSwiftInProcPluginServer.so -plugin-path /usr/lib/swift/host/plugins -plugin-path /usr/local/lib/swift/host/plugins -parse-as-library -o /swift-dns/.build/aarch64-unknown-linux-gnu/debug/DNSClient.build/MessageIDGenerator.swift.o -o /swift-dns/.build/aarch64-unknown-linux-gnu/debug/DNSClient.build/PendingQuery.swift.o -index-store-path /swift-dns/.build/aarch64-unknown-linux-gnu/debug/index/store -index-system-modules
1.	Swift version 6.2-dev (LLVM 0bbdf73817e84bd, Swift 5797130e90a66c5)
2.	Compiling with the current language version
3.	While evaluating request ASTLoweringRequest(Lowering AST to SIL for file "/swift-dns/Sources/DNSClient/MessageIDGenerator.swift")
4.	While silgen emitFunction SIL function "@$s9DNSClient18MessageIDGeneratorV4nexts6UInt16VyAC6ErrorsOYKF".
 for 'next()' (at /swift-dns/Sources/DNSClient/MessageIDGenerator.swift:18:22)
5.	While silgen closureexpr SIL function "@$s9DNSClient18MessageIDGeneratorV4nexts6UInt16VyAC6ErrorsOYKFSiSgSiYbcACYbcfu_".
 for expression at [/swift-dns/Sources/DNSClient/MessageIDGenerator.swift:20:66 - line:20:66] RangeText=""
 #0 0x0000aaaab7d6175c llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/usr/bin/swift-frontend+0x84a175c)
 #1 0x0000aaaab7d5f5e0 llvm::sys::RunSignalHandlers() (/usr/bin/swift-frontend+0x849f5e0)
 #2 0x0000aaaab7d61e70 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
 #3 0x0000ffffa1a86860 (linux-vdso.so.1+0x860)
 #4 0x0000ffff9fbe7608 (/lib/aarch64-linux-gnu/libc.so.6+0x87608)
 #5 0x0000ffff9fb9cb3c raise (/lib/aarch64-linux-gnu/libc.so.6+0x3cb3c)
 #6 0x0000ffff9fb87e00 abort (/lib/aarch64-linux-gnu/libc.so.6+0x27e00)
 #7 0x0000ffff9fb95cc0 (/lib/aarch64-linux-gnu/libc.so.6+0x35cc0)
 #8 0x0000ffff9fb95d30 __assert_perror_fail (/lib/aarch64-linux-gnu/libc.so.6+0x35d30)
 #9 0x0000aaaab0fbc3a0 swift::Lowering::SILGenFunction::emitCaptures(swift::SILLocation, swift::SILDeclRef, swift::Lowering::CaptureEmission, llvm::SmallVectorImpl<swift::Lowering::ManagedValue>&) crtstuff.c:0:0
#10 0x0000aaaab0fbcdf8 swift::Lowering::SILGenFunction::emitClosureValue(swift::SILLocation, swift::SILDeclRef, swift::Lowering::FunctionTypeInfo const&, swift::SubstitutionMap) crtstuff.c:0:0
#11 0x0000aaaab0fb1934 (anonymous namespace)::RValueEmitter::emitClosureReference(swift::AbstractClosureExpr*, swift::Lowering::FunctionTypeInfo const&) SILGenExpr.cpp:0:0
#12 0x0000aaaab0fb165c (anonymous namespace)::RValueEmitter::visitAbstractClosureExpr(swift::AbstractClosureExpr*, swift::Lowering::SGFContext) SILGenExpr.cpp:0:0
#13 0x0000aaaab0f9030c swift::Lowering::SILGenFunction::emitRValue(swift::Expr*, swift::Lowering::SGFContext) crtstuff.c:0:0
#14 0x0000aaaab1033144 swift::Lowering::SILGenFunction::emitReturnExpr(swift::SILLocation, swift::Expr*) crtstuff.c:0:0
#15 0x0000aaaab0fbdab0 swift::Lowering::SILGenFunction::emitClosure(swift::AbstractClosureExpr*) crtstuff.c:0:0
#16 0x0000aaaab0f3fd5c swift::Lowering::SILGenModule::emitFunctionDefinition(swift::SILDeclRef, swift::SILFunction*) crtstuff.c:0:0
#17 0x0000aaaab0f49694 void llvm::function_ref<void ()>::callback_fn<swift::Lowering::SILGenModule::emitClosure(swift::AbstractClosureExpr*, swift::Lowering::FunctionTypeInfo const&)::$_4>(long) SILGen.cpp:0:0
#18 0x0000aaaab19a6374 swift::Lowering::TypeConverter::withClosureTypeInfo(swift::AbstractClosureExpr*, swift::Lowering::FunctionTypeInfo const&, llvm::function_ref<void ()>) (/usr/bin/swift-frontend+0x20e6374)
#19 0x0000aaaab0f433bc swift::Lowering::SILGenModule::emitClosure(swift::AbstractClosureExpr*, swift::Lowering::FunctionTypeInfo const&) crtstuff.c:0:0
#20 0x0000aaaab1086eb8 (anonymous namespace)::SILGenApply::visitAbstractClosureExpr(swift::AbstractClosureExpr*) SILGenApply.cpp:0:0
#21 0x0000aaaab106f128 swift::Lowering::SILGenFunction::emitApplyExpr(swift::ApplyExpr*, swift::Lowering::SGFContext) crtstuff.c:0:0
#22 0x0000aaaab0fa8f90 (anonymous namespace)::RValueEmitter::visitFunctionConversionExpr(swift::FunctionConversionExpr*, swift::Lowering::SGFContext) SILGenExpr.cpp:0:0
#23 0x0000aaaab0f93274 swift::Lowering::SILGenFunction::emitRValueAsSingleValue(swift::Expr*, swift::Lowering::SGFContext) crtstuff.c:0:0
#24 0x0000aaaab107e25c (anonymous namespace)::ArgEmitter::emit(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern, bool, std::optional<swift::AnyFunctionType::Param>) SILGenApply.cpp:0:0
#25 0x0000aaaab106cfec (anonymous namespace)::ArgEmitter::emitSingleArg(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern, bool, std::optional<swift::AnyFunctionType::Param>) SILGenApply.cpp:0:0
#26 0x0000aaaab107c884 (anonymous namespace)::ArgEmitter::emitPreparedArgs(swift::Lowering::PreparedArguments&&, swift::Lowering::AbstractionPattern, llvm::ArrayRef<swift::LifetimeDependenceInfo>) SILGenApply.cpp:0:0
#27 0x0000aaaab1089494 (anonymous namespace)::CallSite::emit(swift::Lowering::SILGenFunction&, swift::Lowering::AbstractionPattern, swift::CanTypeWrapper<swift::SILFunctionType>, llvm::ArrayRef<swift::LifetimeDependenceInfo>, (anonymous namespace)::ParamLowering&, llvm::SmallVectorImpl<swift::Lowering::ManagedValue>&, llvm::SmallVectorImpl<(anonymous namespace)::DelayedArgument>&, swift::ForeignInfo const&) && SILGenApply.cpp:0:0
#28 0x0000aaaab1088a74 (anonymous namespace)::CallEmission::emitArgumentsForNormalApply(swift::Lowering::AbstractionPattern, swift::CanTypeWrapper<swift::SILFunctionType>, llvm::ArrayRef<swift::LifetimeDependenceInfo>, swift::ForeignInfo const&, llvm::SmallVectorImpl<swift::Lowering::ManagedValue>&, std::optional<swift::SILLocation>&) SILGenApply.cpp:0:0
#29 0x0000aaaab10712f8 (anonymous namespace)::CallEmission::apply(swift::Lowering::SGFContext) SILGenApply.cpp:0:0
#30 0x0000aaaab106f64c swift::Lowering::SILGenFunction::emitApplyExpr(swift::ApplyExpr*, swift::Lowering::SGFContext) crtstuff.c:0:0
#31 0x0000aaaab0f9015c swift::Lowering::SILGenFunction::emitExprInto(swift::Expr*, swift::Lowering::Initialization*, std::optional<swift::SILLocation>) crtstuff.c:0:0
#32 0x0000aaaab0f79484 swift::Lowering::SILGenFunction::emitStmtCondition(llvm::MutableArrayRef<swift::StmtConditionElement>, swift::Lowering::JumpDest, swift::SILLocation, swift::ProfileCounter, swift::ProfileCounter) crtstuff.c:0:0
#33 0x0000aaaab10318f0 swift::ASTVisitor<(anonymous namespace)::StmtEmitter, void, void, void, void, void, void>::visit(swift::Stmt*) SILGenStmt.cpp:0:0
#34 0x0000aaaab1030f20 swift::ASTVisitor<(anonymous namespace)::StmtEmitter, void, void, void, void, void, void>::visit(swift::Stmt*) SILGenStmt.cpp:0:0
#35 0x0000aaaab102fda0 swift::Lowering::SILGenFunction::emitStmt(swift::Stmt*) crtstuff.c:0:0
#36 0x0000aaaab0fbd7ac swift::Lowering::SILGenFunction::emitFunction(swift::FuncDecl*) crtstuff.c:0:0
#37 0x0000aaaab0f40c1c swift::Lowering::SILGenModule::emitFunctionDefinition(swift::SILDeclRef, swift::SILFunction*) crtstuff.c:0:0
#38 0x0000aaaab0f42240 swift::Lowering::SILGenModule::emitOrDelayFunction(swift::SILDeclRef) crtstuff.c:0:0
#39 0x0000aaaab0f3f3c0 swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*) crtstuff.c:0:0
#40 0x0000aaaab1048c60 (anonymous namespace)::SILGenType::visitFuncDecl(swift::FuncDecl*) SILGenType.cpp:0:0
#41 0x0000aaaab1044af0 (anonymous namespace)::SILGenType::emitType() SILGenType.cpp:0:0
#42 0x0000aaaab10449e0 swift::Lowering::SILGenModule::visitNominalTypeDecl(swift::NominalTypeDecl*) crtstuff.c:0:0
#43 0x0000aaaab0f44e08 swift::Lowering::SILGenModule::emitSourceFile(swift::SourceFile*) crtstuff.c:0:0
#44 0x0000aaaab0f453d8 swift::ASTLoweringRequest::evaluate(swift::Evaluator&, swift::ASTLoweringDescriptor) const (/usr/bin/swift-frontend+0x16853d8)
#45 0x0000aaaab102f694 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
#46 0x0000aaaab0f4a51c 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
#47 0x0000aaaab0f45bac swift::performASTLowering(swift::FileUnit&, swift::Lowering::TypeConverter&, swift::SILOptions const&, swift::IRGenOptions const*) (/usr/bin/swift-frontend+0x1685bac)
#48 0x0000aaaab07f40e0 swift::performCompileStepsPostSema(swift::CompilerInstance&, int&, swift::FrontendObserver*) (/usr/bin/swift-frontend+0xf340e0)
#49 0x0000aaaab080247c withSemanticAnalysis(swift::CompilerInstance&, swift::FrontendObserver*, llvm::function_ref<bool (swift::CompilerInstance&)>, bool) FrontendTool.cpp:0:0
#50 0x0000aaaab07f6970 performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) FrontendTool.cpp:0:0
#51 0x0000aaaab07f5dc4 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) (/usr/bin/swift-frontend+0xf35dc4)
#52 0x0000aaaab05b1a7c swift::mainEntry(int, char const**) (/usr/bin/swift-frontend+0xcf1a7c)
#53 0x0000ffff9fb884c4 (/lib/aarch64-linux-gnu/libc.so.6+0x284c4)
#54 0x0000ffff9fb88598 __libc_start_main (/lib/aarch64-linux-gnu/libc.so.6+0x28598)
#55 0x0000aaaab05b0c70 _start (/usr/bin/swift-frontend+0xcf0c70)

Expected behavior

No crash.

Environment

Latest swiftlang/swift:nightly-6.2-noble Docker image.
Also macOS 26 + Xcode 26 beta 3 toolchain.

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.crashBug: A crash, i.e., an abnormal termination of softwaretriage neededThis issue needs more specific labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions