Skip to content

Commit f8f172a

Browse files
committed
demangler: also support the future mangling prefix ‘_S’
1 parent be986d7 commit f8f172a

File tree

4 files changed

+28
-6
lines changed

4 files changed

+28
-6
lines changed

lib/Basic/Demangle.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2331,7 +2331,9 @@ class OldDemangler {
23312331
bool
23322332
swift::Demangle::isSwiftSymbol(const char *mangledName) {
23332333
// The old mangling.
2334-
if (mangledName[0] == '_' && mangledName[1] == 'T')
2334+
if (mangledName[0] == '_'
2335+
// Also accept the future mangling prefix.
2336+
&& (mangledName[1] == 'T' || mangledName[1] == 'S'))
23352337
return true;
23362338

23372339
// The new mangling.

lib/Basic/Demangler.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,10 @@ void Context::clear() {
137137

138138
NodePointer Context::demangleSymbolAsNode(llvm::StringRef MangledName) {
139139
#ifndef NO_NEW_DEMANGLING
140-
if (MangledName.startswith(MANGLING_PREFIX_STR)) {
140+
if (MangledName.startswith(MANGLING_PREFIX_STR)
141+
// Also accept the future mangling prefix.
142+
// TODO: remove this line as soon as MANGLING_PREFIX_STR gets "_S".
143+
|| MangledName.startswith("_S")) {
141144
return D->demangleSymbol(MangledName);
142145
}
143146
#endif
@@ -171,7 +174,10 @@ std::string Context::demangleTypeAsString(llvm::StringRef MangledName,
171174
}
172175

173176
bool Context::isThunkSymbol(llvm::StringRef MangledName) {
174-
if (MangledName.startswith(MANGLING_PREFIX_STR)) {
177+
if (MangledName.startswith(MANGLING_PREFIX_STR)
178+
// Also accept the future mangling prefix.
179+
// TODO: remove this line as soon as MANGLING_PREFIX_STR gets "_S".
180+
|| MangledName.startswith("_S")) {
175181
// First do a quick check
176182
if (MangledName.endswith("TA") || // partial application forwarder
177183
MangledName.endswith("Ta") || // ObjC partial application forwarder
@@ -341,7 +347,10 @@ void Demangler::init(StringRef MangledName) {
341347
NodePointer Demangler::demangleSymbol(StringRef MangledName) {
342348
init(MangledName);
343349

344-
if (!nextIf(MANGLING_PREFIX_STR))
350+
if (!nextIf(MANGLING_PREFIX_STR)
351+
// Also accept the future mangling prefix.
352+
// TODO: remove this line as soon as MANGLING_PREFIX_STR gets "_S".
353+
&& !nextIf("_S"))
345354
return nullptr;
346355

347356
NodePointer topLevel = createNode(Node::Kind::Global);

test/Demangle/Inputs/manglings.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ _TToFC3foo3bar3basfT3zimCS_3zim_T_ ---> {TC} @objc foo.bar.bas (zim : foo.zim) -
8181
_TTOFSC3fooFTSdSd_Sd ---> {T} @nonobjc __C.foo (Swift.Double, Swift.Double) -> Swift.Double
8282
_T03foo3barC3basyAA3zimCAE_tFTo ---> {TC} @objc foo.bar.bas (zim : foo.zim) -> ()
8383
_T0SC3fooSdSd_SdtFTO ---> {T} @nonobjc __C.foo (Swift.Double, Swift.Double) -> Swift.Double
84+
_S3foo3barC3basyAA3zimCAE_tFTo ---> {TC} @objc foo.bar.bas (zim : foo.zim) -> ()
85+
_SSC3fooSdSd_SdtFTO ---> {T} @nonobjc __C.foo (Swift.Double, Swift.Double) -> Swift.Double
8486
_TTDFC3foo3bar3basfT3zimCS_3zim_T_ ---> dynamic foo.bar.bas (zim : foo.zim) -> ()
8587
_TFC3foo3bar3basfT3zimCS_3zim_T_ ---> foo.bar.bas (zim : foo.zim) -> ()
8688
_TF3foooi1pFTCS_3barVS_3bas_OS_3zim ---> foo.+ infix (foo.bar, foo.bas) -> foo.zim

tools/swift-demangle/swift-demangle.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,15 @@ static void demangle(llvm::raw_ostream &os, llvm::StringRef name,
9999
// mangling and demangling tests.
100100
remangled = name;
101101
} else {
102+
// Also accept the future mangling prefix.
103+
// TODO: remove the "_S" as soon as MANGLING_PREFIX_STR gets "_S".
102104
remangled = swift::Demangle::mangleNode(pointer,
103-
/*NewMangling*/ name.startswith(MANGLING_PREFIX_STR));
105+
/*NewMangling*/ name.startswith(MANGLING_PREFIX_STR)
106+
|| name.startswith("_S"));
107+
if (name.startswith("_S")) {
108+
assert(remangled.find(MANGLING_PREFIX_STR) == 0);
109+
remangled = "_S" + remangled.substr(3);
110+
}
104111
if (name != remangled) {
105112
llvm::errs() << "\nError: re-mangled name \n " << remangled
106113
<< "\ndoes not match original name\n " << name << '\n';
@@ -144,7 +151,9 @@ static void demangle(llvm::raw_ostream &os, llvm::StringRef name,
144151

145152
static int demangleSTDIN(const swift::Demangle::DemangleOptions &options) {
146153
// This doesn't handle Unicode symbols, but maybe that's okay.
147-
llvm::Regex maybeSymbol("(_T|" MANGLING_PREFIX_STR ")[_a-zA-Z0-9$]+");
154+
// Also accept the future mangling prefix.
155+
// TODO: remove the "_S" as soon as MANGLING_PREFIX_STR gets "_S".
156+
llvm::Regex maybeSymbol("(_T|_S|" MANGLING_PREFIX_STR ")[_a-zA-Z0-9$]+");
148157

149158
swift::Demangle::Context DCtx;
150159
for (std::string mangled; std::getline(std::cin, mangled);) {

0 commit comments

Comments
 (0)