Skip to content

[cxxinterop] UNREACHABLE in AstMangler when mangling C++ type imported via global using declaration #82108

Closed
@ADKaster

Description

@ADKaster

Description

This is a reduction of LadybirdBrowser/ladybird#1102 by @orobio

When a C++ class inside a namespace is imported into the global namespace via using decl, the resulting class is unusable from swift with debug info turned on (-g).

Reproduction

test.h

namespace Test {
  class Foo {};
}

using Test::Foo;

module.modulemap

module Test {
  header "test.h"
  export *
  requires cplusplus
}

test.swift

import Test

func f(_ foo: Foo) {}

Command:

swiftc -g -cxx-interoperability-mode=default -I. test.swift

Stack dump

error: compile command failed due to signal 6 (use -v to see invocation)
unknown imported Clang type
UNREACHABLE executed at /home/build-user/swift/lib/AST/ASTMangler.cpp:3178!
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the crash backtrace.
Stack dump:
0.	Program arguments: /home/andrew/.local/share/swiftly/toolchains/main-snapshot-2025-06-03/usr/bin/swift-frontend -frontend -c -primary-file test.swift -target x86_64-unknown-linux-gnu -disable-objc-interop -cxx-interoperability-mode=default -I . -color-diagnostics -Xcc -fcolor-diagnostics -g -debug-info-format=dwarf -dwarf-version=4 -empty-abi-descriptor -enable-anonymous-context-mangled-names -file-compilation-dir /home/andrew/ladybird-org/swift-test-apps/using-namespace -no-auto-bridging-header-chaining -module-name test -in-process-plugin-server-path /home/andrew/.local/share/swiftly/toolchains/main-snapshot-2025-06-03/usr/lib/swift/host/libSwiftInProcPluginServer.so -plugin-path /home/andrew/.local/share/swiftly/toolchains/main-snapshot-2025-06-03/usr/lib/swift/host/plugins -plugin-path /home/andrew/.local/share/swiftly/toolchains/main-snapshot-2025-06-03/usr/local/lib/swift/host/plugins -o /tmp/TemporaryDirectory.TY0bSq/test-2.o
1.	Swift version 6.2-dev (LLVM b5d039be1fbae13, Swift 4fb4945ab972c85)
2.	Compiling with effective version 5.10
3.	While evaluating request IRGenRequest(IR Generation for file "test.swift")
4.	While emitting IR SIL function "@$s4test1fyySo4TestO3FooVF".
 for 'f(_:)' (at test.swift:3:1)
5.	While mangling type for debugger type 'Foo' (declared at [/home/andrew/ladybird-org/swift-test-apps/using-namespace/./test.h:5:13 - line:5:13] RangeText="")
 #0 0x0000616dffebba88 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/andrew/.local/share/swiftly/toolchains/main-snapshot-2025-06-03/usr/bin/swift-frontend+0x8c10a88)
 #1 0x0000616dffeb962e llvm::sys::RunSignalHandlers() (/home/andrew/.local/share/swiftly/toolchains/main-snapshot-2025-06-03/usr/bin/swift-frontend+0x8c0e62e)
 #2 0x0000616dffebc121 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
 #3 0x00007d412a845330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)
 #4 0x00007d412a89eb2c __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
 #5 0x00007d412a89eb2c __pthread_kill_internal ./nptl/pthread_kill.c:78:10
 #6 0x00007d412a89eb2c pthread_kill ./nptl/pthread_kill.c:89:10
 #7 0x00007d412a84527e raise ./signal/../sysdeps/posix/raise.c:27:6
 #8 0x00007d412a8288ff abort ./stdlib/abort.c:81:7
 #9 0x0000616dffe0e440 llvm::install_out_of_memory_new_handler() (/home/andrew/.local/share/swiftly/toolchains/main-snapshot-2025-06-03/usr/bin/swift-frontend+0x8b63440)
#10 0x0000616df9e278fd (/home/andrew/.local/share/swiftly/toolchains/main-snapshot-2025-06-03/usr/bin/swift-frontend+0x2b7c8fd)
#11 0x0000616df9e1b2dd swift::Mangle::ASTMangler::appendType(swift::Type, swift::GenericSignature, swift::ValueDecl const*) (/home/andrew/.local/share/swiftly/toolchains/main-snapshot-2025-06-03/usr/bin/swift-frontend+0x2b702dd)
#12 0x0000616df9e1f7bb swift::Mangle::ASTMangler::mangleTypeForDebugger[abi:cxx11](swift::Type, swift::GenericSignature) (/home/andrew/.local/share/swiftly/toolchains/main-snapshot-2025-06-03/usr/bin/swift-frontend+0x2b747bb)
#13 0x0000616df8977055 (anonymous namespace)::IRGenDebugInfoImpl::getMangledName(swift::irgen::DebugTypeInfo) IRGenDebugInfo.cpp:0:0
#14 0x0000616df89737e3 (anonymous namespace)::IRGenDebugInfoImpl::getOrCreateType(swift::irgen::DebugTypeInfo, llvm::DIScope*) IRGenDebugInfo.cpp:0:0
#15 0x0000616df896d19d (anonymous namespace)::IRGenDebugInfoImpl::emitVariableDeclaration(swift::irgen::IRBuilder&, llvm::ArrayRef<llvm::Value*>, swift::irgen::DebugTypeInfo, swift::SILDebugScope const*, std::optional<swift::SILLocation>, swift::SILDebugVariable, swift::irgen::IndirectionKind, swift::irgen::ArtificialKind, swift::irgen::AddrDbgInstrKind) IRGenDebugInfo.cpp:0:0
#16 0x0000616df896cf0c swift::irgen::IRGenDebugInfo::emitVariableDeclaration(swift::irgen::IRBuilder&, llvm::ArrayRef<llvm::Value*>, swift::irgen::DebugTypeInfo, swift::SILDebugScope const*, std::optional<swift::SILLocation>, swift::SILDebugVariable, swift::irgen::IndirectionKind, swift::irgen::ArtificialKind, swift::irgen::AddrDbgInstrKind) (/home/andrew/.local/share/swiftly/toolchains/main-snapshot-2025-06-03/usr/bin/swift-frontend+0x16c1f0c)
#17 0x0000616df89a66f7 (anonymous namespace)::IRGenSILFunction::visitSILBasicBlock(swift::SILBasicBlock*) IRGenSIL.cpp:0:0
#18 0x0000616df898ec90 (anonymous namespace)::IRGenSILFunction::emitSILFunction() IRGenSIL.cpp:0:0
#19 0x0000616df898b835 swift::irgen::IRGenModule::emitSILFunction(swift::SILFunction*) (/home/andrew/.local/share/swiftly/toolchains/main-snapshot-2025-06-03/usr/bin/swift-frontend+0x16e0835)
#20 0x0000616df882374f swift::irgen::IRGenerator::emitGlobalTopLevel(std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>> const&) (/home/andrew/.local/share/swiftly/toolchains/main-snapshot-2025-06-03/usr/bin/swift-frontend+0x157874f)
#21 0x0000616df8698cfe swift::IRGenRequest::evaluate(swift::Evaluator&, swift::IRGenDescriptor) const (/home/andrew/.local/share/swiftly/toolchains/main-snapshot-2025-06-03/usr/bin/swift-frontend+0x13edcfe)
#22 0x0000616df870e9bc swift::GeneratedModule swift::SimpleRequest<swift::IRGenRequest, swift::GeneratedModule (swift::IRGenDescriptor), (swift::RequestFlags)17>::callDerived<0ul>(swift::Evaluator&, std::integer_sequence<unsigned long, 0ul>) const crtstuff.c:0:0
#23 0x0000616df870e919 swift::SimpleRequest<swift::IRGenRequest, swift::GeneratedModule (swift::IRGenDescriptor), (swift::RequestFlags)17>::evaluateRequest(swift::IRGenRequest const&, swift::Evaluator&) crtstuff.c:0:0
#24 0x0000616df86a32b4 swift::IRGenRequest::OutputType swift::Evaluator::getResultUncached<swift::IRGenRequest, swift::IRGenRequest::OutputType swift::evaluateOrFatal<swift::IRGenRequest>(swift::Evaluator&, swift::IRGenRequest)::'lambda'()>(swift::IRGenRequest const&, swift::IRGenRequest::OutputType swift::evaluateOrFatal<swift::IRGenRequest>(swift::Evaluator&, swift::IRGenRequest)::'lambda'()) crtstuff.c:0:0
#25 0x0000616df869b4d8 swift::performIRGeneration(swift::FileUnit*, swift::IRGenOptions const&, swift::TBDGenOptions const&, std::unique_ptr<swift::SILModule, std::default_delete<swift::SILModule>>, llvm::StringRef, swift::PrimarySpecificPaths const&, llvm::StringRef, llvm::GlobalVariable**) (/home/andrew/.local/share/swiftly/toolchains/main-snapshot-2025-06-03/usr/bin/swift-frontend+0x13f04d8)
#26 0x0000616df8208a76 generateIR(swift::IRGenOptions const&, swift::TBDGenOptions const&, std::unique_ptr<swift::SILModule, std::default_delete<swift::SILModule>>, swift::PrimarySpecificPaths const&, llvm::StringRef, llvm::PointerUnion<swift::ModuleDecl*, swift::SourceFile*>, llvm::GlobalVariable*&, llvm::ArrayRef<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>) FrontendTool.cpp:0:0
#27 0x0000616df8204365 performCompileStepsPostSILGen(swift::CompilerInstance&, std::unique_ptr<swift::SILModule, std::default_delete<swift::SILModule>>, llvm::PointerUnion<swift::ModuleDecl*, swift::SourceFile*>, swift::PrimarySpecificPaths const&, int&, swift::FrontendObserver*) FrontendTool.cpp:0:0
#28 0x0000616df8202e32 swift::performCompileStepsPostSema(swift::CompilerInstance&, int&, swift::FrontendObserver*) (/home/andrew/.local/share/swiftly/toolchains/main-snapshot-2025-06-03/usr/bin/swift-frontend+0xf57e32)
#29 0x0000616df8214cfa withSemanticAnalysis(swift::CompilerInstance&, swift::FrontendObserver*, llvm::function_ref<bool (swift::CompilerInstance&)>, bool) FrontendTool.cpp:0:0
#30 0x0000616df8205efe performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) FrontendTool.cpp:0:0
#31 0x0000616df8205043 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) (/home/andrew/.local/share/swiftly/toolchains/main-snapshot-2025-06-03/usr/bin/swift-frontend+0xf5a043)
#32 0x0000616df7f78c3a swift::mainEntry(int, char const**) (/home/andrew/.local/share/swiftly/toolchains/main-snapshot-2025-06-03/usr/bin/swift-frontend+0xccdc3a)
#33 0x00007d412a82a1ca __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:74:3
#34 0x00007d412a82a28b call_init ./csu/../csu/libc-start.c:128:20
#35 0x00007d412a82a28b __libc_start_main ./csu/../csu/libc-start.c:347:5
#36 0x0000616df7f77c35 _start (/home/andrew/.local/share/swiftly/toolchains/main-snapshot-2025-06-03/usr/bin/swift-frontend+0xcccc35)

Expected behavior

Same behavior as without -g: compiles without error.

Environment

Swift version 6.2-dev (LLVM b5d039be1fbae13, Swift 4fb4945)
Target: x86_64-unknown-linux-gnu
Build config: +assertions

swiftly main-snapshot-2025-06-03

Additional information

cc @Xazax-hun

After digging into the Swift compiler, @orobio found that the specific UsingShadowDecl type resulting from using Test::Foo; isn't handled properly when mangling. As a workaround, you could use using Foo = Test::Foo; instead, which produces a different declaration type.

Metadata

Metadata

Assignees

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