Skip to content

Commit 7e456ca

Browse files
committed
---
yaml --- r: 347630 b: refs/heads/master c: d9602be h: refs/heads/master
1 parent c8f81a7 commit 7e456ca

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 178406c9c2eff4787bc712370ca7e0c5a4bde455
2+
refs/heads/master: d9602be71598fe7fb927202077b0615b8007bbc5
33
refs/heads/master-next: 203b3026584ecad859eb328b2e12490099409cd5
44
refs/tags/osx-passed: b6b74147ef8a386f532cf9357a1bde006e552c54
55
refs/tags/swift-2.2-SNAPSHOT-2015-12-01-a: 6bb18e013c2284f2b45f5f84f2df2887dc0f7dea

trunk/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") ||

trunk/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)