Skip to content

Commit f8d78e2

Browse files
committed
Handle demangling prefix @__swiftmacro_ used for filenames.
1 parent 6905bc0 commit f8d78e2

File tree

4 files changed

+12
-2
lines changed

4 files changed

+12
-2
lines changed

docs/ABI/Mangling.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Mangling
99
::
1010

1111
mangled-name ::= '$s' global // Swift stable mangling
12+
mangled-name ::= '@__swiftmacro_' global // Swift mangling for filenames
1213
mangled-name ::= '_T0' global // Swift 4.0
1314
mangled-name ::= '$S' global // Swift 4.2
1415

lib/Demangling/Demangler.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,9 @@ int swift::Demangle::getManglingPrefixLength(llvm::StringRef mangledName) {
177177
llvm::StringRef prefixes[] = {
178178
/*Swift 4*/ "_T0",
179179
/*Swift 4.x*/ "$S", "_$S",
180-
/*Swift 5+*/ "$s", "_$s"};
180+
/*Swift 5+*/ "$s", "_$s",
181+
/*Swift 5+ for filenames*/ "@__swiftmacro_",
182+
};
181183

182184
// Look for any of the known prefixes
183185
for (auto prefix : prefixes) {

test/Demangle/Inputs/manglings.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,3 +452,4 @@ $s4main4TestV1xSivpfaAA4Flag ---> runtime attribute generator of main.Test.x : S
452452
$s4main4TestAaBVmvpfaAA9OtherFlag ---> runtime attribute generator of main.Test : main.Test.Type for attribute = main.OtherFlag
453453
$s9MacroUser13testStringify1a1bySi_SitF9stringifyfMf1_ ---> freestanding macro expansion #3 of stringify in MacroUser.testStringify(a: Swift.Int, b: Swift.Int) -> ()
454454
$s9MacroUser016testFreestandingA9ExpansionyyF4Foo3L_V23bitwidthNumberedStructsfMf_6methodfMu0_ ---> unique name #2 of method in freestanding macro expansion #1 of bitwidthNumberedStructs in Foo3 #1 in MacroUser.testFreestandingMacroExpansion() -> ()
455+
@__swiftmacro_1a13testStringifyAA1bySi_SitF9stringifyfMf_ ---> freestanding macro expansion #1 of stringify in a.testStringify(a: Swift.Int, b: Swift.Int) -> ()

tools/swift-demangle/swift-demangle.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ static bool findMaybeMangled(llvm::StringRef input, llvm::StringRef &match) {
271271
} state = Start;
272272
const char *matchStart = nullptr;
273273

274-
// Find _T, $S, $s, _$S, _$s followed by a valid mangled string
274+
// Find _T, $S, $s, _$S, _$s, @__swift_ followed by a valid mangled string
275275
while (ptr < end) {
276276
switch (state) {
277277
case Start:
@@ -286,6 +286,12 @@ static bool findMaybeMangled(llvm::StringRef input, llvm::StringRef &match) {
286286
state = SeenDollar;
287287
matchStart = ptr - 1;
288288
break;
289+
} else if (ch == '@' &&
290+
llvm::StringRef(ptr, end - ptr).startswith("__swiftmacro_")){
291+
matchStart = ptr - 1;
292+
ptr = ptr + strlen("__swift_");
293+
state = FoundPrefix;
294+
break;
289295
}
290296
}
291297
break;

0 commit comments

Comments
 (0)