Skip to content

Commit 01bd68e

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
1 parent da3cfae commit 01bd68e

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
@@ -2514,10 +2514,19 @@ void ASTMangler::appendModule(const ModuleDecl *module,
25142514
// For example, if a module Foo has 'import Bar', and '-module-alias Bar=Baz'
25152515
// was passed, the name 'Baz' will be used for mangling besides loading.
25162516
StringRef ModName = module->getRealName().str();
2517-
if (RespectOriginallyDefinedIn &&
2518-
module->getABIName() != module->getName()) { // check if the ABI name is set
2517+
2518+
// If RespectOriginallyDefinedIn is not set, ignore the ABI name only for
2519+
// _Concurrency and swift-syntax (which adds "Compiler" as a prefix when
2520+
// building swift-syntax as part of the compiler).
2521+
// TODO: Mangling for the debugger should respect originally defined in, but
2522+
// as of right now there is not enough information in the mangled name to
2523+
// reconstruct AST types from mangled names when using that attribute.
2524+
if ((RespectOriginallyDefinedIn ||
2525+
(module->getName().str() != SWIFT_CONCURRENCY_NAME &&
2526+
!module->getABIName().str().starts_with(
2527+
SWIFT_MODULE_ABI_NAME_PREFIX))) &&
2528+
module->getABIName() != module->getName())
25192529
ModName = module->getABIName().str();
2520-
}
25212530

25222531
// Try the special 'swift' substitution.
25232532
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)