Skip to content

Commit 7bb8b57

Browse files
committed
Respect the module ABI name when mangling for the debugger
The mangled name produced for the debugger should match the one emitted in reflection metadata, otherwise LLDB will not be able to lookup types when the module is compiled with the -module-abi-name flag. rdar://125848324 (cherry picked from commit 01bd68e)
1 parent 055888f commit 7bb8b57

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

include/swift/Strings.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ constexpr static const StringLiteral SWIFT_ONONE_SUPPORT = "SwiftOnoneSupport";
2626
constexpr static const StringLiteral SWIFT_CONCURRENCY_NAME = "_Concurrency";
2727
/// The name of the Concurrency Shims Clang module
2828
constexpr static const StringLiteral SWIFT_CONCURRENCY_SHIMS_NAME = "_SwiftConcurrencyShims";
29+
/// The unique ABI prefix that swift-syntax uses when it's built as part of the
30+
/// compiler.
31+
constexpr static const StringLiteral SWIFT_MODULE_ABI_NAME_PREFIX = "Compiler";
2932
/// The name of the Distributed module, which supports that extension.
3033
constexpr static const StringLiteral SWIFT_DISTRIBUTED_NAME = "Distributed";
3134
/// The name of the StringProcessing module, which supports that extension.

lib/AST/ASTMangler.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2509,10 +2509,19 @@ void ASTMangler::appendModule(const ModuleDecl *module,
25092509
// For example, if a module Foo has 'import Bar', and '-module-alias Bar=Baz'
25102510
// was passed, the name 'Baz' will be used for mangling besides loading.
25112511
StringRef ModName = module->getRealName().str();
2512-
if (RespectOriginallyDefinedIn &&
2513-
module->getABIName() != module->getName()) { // check if the ABI name is set
2512+
2513+
// If RespectOriginallyDefinedIn is not set, ignore the ABI name only for
2514+
// _Concurrency and swift-syntax (which adds "Compiler" as a prefix when
2515+
// building swift-syntax as part of the compiler).
2516+
// TODO: Mangling for the debugger should respect originally defined in, but
2517+
// as of right now there is not enough information in the mangled name to
2518+
// reconstruct AST types from mangled names when using that attribute.
2519+
if ((RespectOriginallyDefinedIn ||
2520+
(module->getName().str() != SWIFT_CONCURRENCY_NAME &&
2521+
!module->getABIName().str().starts_with(
2522+
SWIFT_MODULE_ABI_NAME_PREFIX))) &&
2523+
module->getABIName() != module->getName())
25142524
ModName = module->getABIName().str();
2515-
}
25162525

25172526
// Try the special 'swift' substitution.
25182527
if (ModName == STDLIB_NAME) {

test/DebugInfo/module_abi_name.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// RUN: %target-swift-frontend -primary-file %s -emit-ir -g -module-name=Hello -module-abi-name Goodbye -emit-ir -o - | %FileCheck %s
2+
3+
class SomeClass {}
4+
// CHECK: DICompositeType(tag: DW_TAG_structure_type, name: "SomeClass",{{.*}}runtimeLang: DW_LANG_Swift, identifier: "$s7Goodbye9SomeClassCD"
5+
6+
@available(macOS 10.13, *)
7+
@_originallyDefinedIn(module: "ThirdModule", OSX 10.12)
8+
class DefinedElsewhere {}
9+
// CHECK: DICompositeType(tag: DW_TAG_structure_type, name: "DefinedElsewhere",{{.*}}runtimeLang: DW_LANG_Swift, identifier: "$s7Goodbye16DefinedElsewhereCD")
10+
11+
let v1 = SomeClass()
12+
let v2 = DefinedElsewhere()
13+

0 commit comments

Comments
 (0)