Skip to content

Commit 93c7643

Browse files
authored
Merge pull request #61330 from al45tair/eng/PR-100424460
[Demangler] Fix isThunkSymbol() to handle continuations.
2 parents 18156d1 + 54ea4b2 commit 93c7643

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

lib/Demangling/Context.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,24 @@ static llvm::StringRef stripSuffix(llvm::StringRef Name) {
9494
return Name;
9595
}
9696

97+
// Removes a 'TQ<index>' or 'TY<index>' from \p Name.
98+
static llvm::StringRef stripAsyncContinuation(llvm::StringRef Name) {
99+
if (!Name.endswith("_"))
100+
return Name;
101+
102+
StringRef Stripped = Name.drop_back();
103+
while (!Stripped.empty() && swift::Mangle::isDigit(Stripped.back()))
104+
Stripped = Stripped.drop_back();
105+
106+
if (Stripped.endswith("TQ") || Stripped.endswith("TY"))
107+
return Stripped.drop_back(2);
108+
109+
return Name;
110+
}
111+
97112
bool Context::isThunkSymbol(llvm::StringRef MangledName) {
98113
if (isMangledName(MangledName)) {
99-
MangledName = stripSuffix(MangledName);
114+
MangledName = stripAsyncContinuation(stripSuffix(MangledName));
100115
// First do a quick check
101116
if (MangledName.endswith("TA") || // partial application forwarder
102117
MangledName.endswith("Ta") || // ObjC partial application forwarder
@@ -152,6 +167,9 @@ std::string Context::getThunkTarget(llvm::StringRef MangledName) {
152167
if (stripSuffix(MangledName) != MangledName)
153168
return std::string();
154169

170+
// Ignore any async continuation suffix
171+
MangledName = stripAsyncContinuation(MangledName);
172+
155173
// The targets of those thunks not derivable from the mangling.
156174
if (MangledName.endswith("TR") ||
157175
MangledName.endswith("Tr") ||

test/Demangle/Inputs/manglings.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,3 +434,8 @@ $s4test3fooyyAA1P_pSS1TAaCPRts_Si1UAERtsXPF ---> test.foo(any test.P<Self.test.P
434434
$s4test3FooVAAyyAA1P_pF ---> test.Foo.test(test.P) -> ()
435435
$sxxxIxzCXxxxesy -> $sxxxIxzCXxxxesy
436436
$Sxxx_x_xxIxzCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC$x -> $Sxxx_x_xxIxzCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC$x
437+
$sxIeghHr_xs5Error_pIegHrzo_s8SendableRzs5NeverORs_r0_lTRTATQ0_ ---> {T:$sxIeghHr_xs5Error_pIegHrzo_s8SendableRzs5NeverORs_r0_lTR} (1) await resume partial function for partial apply forwarder for reabstraction thunk helper <A, B where A: Swift.Sendable, B == Swift.Never> from @escaping @callee_guaranteed @Sendable @async () -> (@out A) to @escaping @callee_guaranteed @async () -> (@out A, @error @owned Swift.Error)
438+
$sxIeghHr_xs5Error_pIegHrzo_s8SendableRzs5NeverORs_r0_lTRTQ0_ ---> {T:} (1) await resume partial function for reabstraction thunk helper <A, B where A: Swift.Sendable, B == Swift.Never> from @escaping @callee_guaranteed @Sendable @async () -> (@out A) to @escaping @callee_guaranteed @async () -> (@out A, @error @owned Swift.Error)
439+
$sxIeghHr_xs5Error_pIegHrzo_s8SendableRzs5NeverORs_r0_lTRTY0_ ---> {T:} (1) suspend resume partial function for reabstraction thunk helper <A, B where A: Swift.Sendable, B == Swift.Never> from @escaping @callee_guaranteed @Sendable @async () -> (@out A) to @escaping @callee_guaranteed @async () -> (@out A, @error @owned Swift.Error)
440+
$sxIeghHr_xs5Error_pIegHrzo_s8SendableRzs5NeverORs_r0_lTRTY_ ---> {T:} (0) suspend resume partial function for reabstraction thunk helper <A, B where A: Swift.Sendable, B == Swift.Never> from @escaping @callee_guaranteed @Sendable @async () -> (@out A) to @escaping @callee_guaranteed @async () -> (@out A, @error @owned Swift.Error)
441+
$sxIeghHr_xs5Error_pIegHrzo_s8SendableRzs5NeverORs_r0_lTRTQ12_ ---> {T:} (13) await resume partial function for reabstraction thunk helper <A, B where A: Swift.Sendable, B == Swift.Never> from @escaping @callee_guaranteed @Sendable @async () -> (@out A) to @escaping @callee_guaranteed @async () -> (@out A, @error @owned Swift.Error)

0 commit comments

Comments
 (0)