Skip to content

Commit b5a0906

Browse files
committed
ASTMangler: ignore original module name when DWARFMangling is enabled
Enabling DWARFMangling indicates the mangled name will be used by either debugger or IDE. We could and should avoid using the original module name so demangling will keep working.
1 parent 944d88f commit b5a0906

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

lib/AST/ASTMangler.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,7 @@ std::string ASTMangler::mangleTypeAsUSR(Type Ty) {
499499

500500
std::string ASTMangler::mangleDeclAsUSR(const ValueDecl *Decl,
501501
StringRef USRPrefix) {
502+
DWARFMangling = true;
502503
beginManglingWithoutPrefix();
503504
llvm::SaveAndRestore<bool> allowUnnamedRAII(AllowNamelessEntities, true);
504505
Buffer << USRPrefix;
@@ -1790,7 +1791,12 @@ void ASTMangler::appendModule(const ModuleDecl *module,
17901791
assert(useModuleName.empty());
17911792
return appendOperator("SC");
17921793
}
1793-
if (!useModuleName.empty())
1794+
1795+
// Enabling DWARFMangling indicate the mangled names are not part of the ABI,
1796+
// probably used by the debugger or IDE (USR). These mangled names will not be
1797+
// demangled successfully if we use the original module name instead of the
1798+
// actual module name.
1799+
if (!useModuleName.empty() && !DWARFMangling)
17941800
appendIdentifier(useModuleName);
17951801
else
17961802
appendIdentifier(ModName);

test/IDE/reconstruct_type_from_mangled_name.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,3 +247,9 @@ private
247247
func patatino<T: Comparable>(_ vers1: T, _ vers2: T) -> Bool {
248248
return vers1 < vers2;
249249
}
250+
251+
@available(OSX 10.9, *)
252+
@_originallyDefinedIn(module: "OtherModule", OSX 10.13)
253+
public struct MovedHere {
254+
public func foo() {}
255+
}

0 commit comments

Comments
 (0)