@@ -68,8 +68,24 @@ std::string Context::demangleTypeAsString(llvm::StringRef MangledName,
68
68
return demangling;
69
69
}
70
70
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
+
71
86
bool Context::isThunkSymbol (llvm::StringRef MangledName) {
72
87
if (isMangledName (MangledName)) {
88
+ MangledName = stripSuffix (MangledName);
73
89
// First do a quick check
74
90
if (MangledName.endswith (" TA" ) || // partial application forwarder
75
91
MangledName.endswith (" Ta" ) || // ObjC partial application forwarder
@@ -121,6 +137,10 @@ std::string Context::getThunkTarget(llvm::StringRef MangledName) {
121
137
return std::string ();
122
138
123
139
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
+
124
144
// The targets of those thunks not derivable from the mangling.
125
145
if (MangledName.endswith (" TR" ) ||
126
146
MangledName.endswith (" Tr" ) ||
0 commit comments