Skip to content

Commit 54a3989

Browse files
committed
[lldb] Prevent IsSwiftMangledName false positives (#3984)
Some non-swift symbols can unintentionally cause `isSwiftSymbol` to return true. Any symbol starting with `_T` is considered a swift symbol because "old-style" mangling used this prefix. Prevent this by special casing `_T`-prefixed symbols. The only kind of old-style mangled that lldb should expect to see are ObjC class and protocol names. Classes use a `_TtC` or `_TtGC` prefix (the latter is for generics). Protocols are `_TtP`. (cherry picked from commit 06653e8)
1 parent 37c6aad commit 54a3989

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

lldb/source/Plugins/LanguageRuntime/Swift/SwiftLanguageRuntimeNames.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,15 @@ bool SwiftLanguageRuntime::IsSymbolARuntimeThunk(const Symbol &symbol) {
607607
}
608608

609609
bool SwiftLanguageRuntime::IsSwiftMangledName(llvm::StringRef name) {
610+
// Old-style mangling uses a "_T" prefix. This can lead to false positives
611+
// with other symbols that just so happen to start with "_T". To prevent this,
612+
// only return true for select old-style mangled names. The known cases to are
613+
// ObjC classes and protocols. Classes are prefixed with either "_TtC" or
614+
// "_TtGC" (generic classes). Protocols are prefixed with "_TtP". Other "_T"
615+
// prefixed symbols are not considered to be Swift symbols.
616+
if (name.startswith("_T"))
617+
return name.startswith("_TtC") || name.startswith("_TtGC") ||
618+
name.startswith("_TtP");
610619
return swift::Demangle::isSwiftSymbol(name);
611620
}
612621

lldb/test/API/lang/swift/printdecl/TestSwiftTypeLookup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def test_swift_type_lookup(self):
9595

9696
# check that mangled name lookup works
9797
self.expect(
98-
'type lookup _TtSi',
98+
'type lookup _$sSiD',
9999
substrs=[
100100
'struct Int',
101101
'extension Swift.Int'])

0 commit comments

Comments
 (0)