Skip to content

Commit 91483d2

Browse files
authored
Merge pull request swiftlang#24218 from eeckstein/demangler-thunk-with-suffix
Demangler: handle symbols with .<n> suffix in isThunkSymbol()
2 parents faa6693 + 65bbb9c commit 91483d2

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

lib/Demangling/Context.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,24 @@ std::string Context::demangleTypeAsString(llvm::StringRef MangledName,
6868
return demangling;
6969
}
7070

71+
// Removes a '.<n>' suffix from \p Name. <n> is either a number or a combination of
72+
// '.<other-text>.<n>'.
73+
// Such symbols are produced in IRGen or in LLVM optimizations.
74+
static llvm::StringRef stripSuffix(llvm::StringRef Name) {
75+
// A suffix always ends with a digit. Do this quick check to avoid scanning through the whole
76+
// symbol name if the symbol has no suffix (= the common case).
77+
if (isdigit(Name.back())) {
78+
size_t dotPos = Name.find('.');
79+
if (dotPos != StringRef::npos) {
80+
Name = Name.substr(0, dotPos);
81+
}
82+
}
83+
return Name;
84+
}
85+
7186
bool Context::isThunkSymbol(llvm::StringRef MangledName) {
7287
if (isMangledName(MangledName)) {
88+
MangledName = stripSuffix(MangledName);
7389
// First do a quick check
7490
if (MangledName.endswith("TA") || // partial application forwarder
7591
MangledName.endswith("Ta") || // ObjC partial application forwarder
@@ -121,6 +137,10 @@ std::string Context::getThunkTarget(llvm::StringRef MangledName) {
121137
return std::string();
122138

123139
if (isMangledName(MangledName)) {
140+
// If the symbol has a suffix we cannot derive the target.
141+
if (stripSuffix(MangledName) != MangledName)
142+
return std::string();
143+
124144
// The targets of those thunks not derivable from the mangling.
125145
if (MangledName.endswith("TR") ||
126146
MangledName.endswith("Tr") ||

test/Demangle/Inputs/manglings.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ _$S3foo3barC3bas3zimyAaEC_tFTo ---> {T:_$S3foo3barC3bas3zimyAaEC_tF,C} @objc foo
9393
_$SSC3fooyS2d_SdtFTO ---> {T:_$SSC3fooyS2d_SdtF} @nonobjc __C_Synthesized.foo(Swift.Double, Swift.Double) -> Swift.Double
9494
_$S3foo3barC3bas3zimyAaEC_tFTo ---> {T:_$S3foo3barC3bas3zimyAaEC_tF,C} @objc foo.bar.bas(zim: foo.zim) -> ()
9595
_$SSC3fooyS2d_SdtFTO ---> {T:_$SSC3fooyS2d_SdtF} @nonobjc __C_Synthesized.foo(Swift.Double, Swift.Double) -> Swift.Double
96+
_$sTA.123 ---> {T:} partial apply forwarder with unmangled suffix ".123"
9697
_TTDFC3foo3bar3basfT3zimCS_3zim_T_ ---> dynamic foo.bar.bas(zim: foo.zim) -> ()
9798
_TFC3foo3bar3basfT3zimCS_3zim_T_ ---> foo.bar.bas(zim: foo.zim) -> ()
9899
_TF3foooi1pFTCS_3barVS_3bas_OS_3zim ---> foo.+ infix(foo.bar, foo.bas) -> foo.zim

0 commit comments

Comments
 (0)