Skip to content

Commit 14697d7

Browse files
committed
demangler: classify allocating init functions as thunks
rdar://problem/45170658
1 parent b259271 commit 14697d7

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

include/swift/Demangling/Demangle.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ class Context {
357357
/// Returns true if the mangledName refers to a thunk function.
358358
///
359359
/// Thunk functions are either (ObjC) partial apply forwarder, swift-as-ObjC
360-
/// or ObjC-as-swift thunks.
360+
/// or ObjC-as-swift thunks or allocating init functions.
361361
bool isThunkSymbol(llvm::StringRef MangledName);
362362

363363
/// Returns the mangled name of the target of a thunk.

lib/Demangling/Context.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ bool Context::isThunkSymbol(llvm::StringRef MangledName) {
7777
MangledName.endswith("TO") || // ObjC-as-swift thunk
7878
MangledName.endswith("TR") || // reabstraction thunk helper function
7979
MangledName.endswith("Tr") || // reabstraction thunk
80-
MangledName.endswith("TW")) { // protocol witness thunk
80+
MangledName.endswith("TW") || // protocol witness thunk
81+
MangledName.endswith("fC")) { // allocating constructor
8182

8283
// To avoid false positives, we need to fully demangle the symbol.
8384
NodePointer Nd = D->demangleSymbol(MangledName);
@@ -93,6 +94,7 @@ bool Context::isThunkSymbol(llvm::StringRef MangledName) {
9394
case Node::Kind::ReabstractionThunkHelper:
9495
case Node::Kind::ReabstractionThunk:
9596
case Node::Kind::ProtocolWitness:
97+
case Node::Kind::Allocator:
9698
return true;
9799
default:
98100
break;
@@ -125,6 +127,12 @@ std::string Context::getThunkTarget(llvm::StringRef MangledName) {
125127
MangledName.endswith("TW") )
126128
return std::string();
127129

130+
if (MangledName.endswith("fC")) {
131+
std::string target = MangledName.str();
132+
target[target.size() - 1] = 'c';
133+
return target;
134+
}
135+
128136
return MangledName.substr(0, MangledName.size() - 2).str();
129137
}
130138
// Old mangling.

test/Demangle/Inputs/manglings.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ _T03nix6testitSaySiGyFTv0_ ---> outlined variable #1 of nix.testit() -> [Swift.I
286286
_T0So11UITextFieldC4textSSSgvgToTepb_ ---> outlined bridged method (pb) of @objc __C.UITextField.text.getter : Swift.String?
287287
_T0So11UITextFieldC4textSSSgvgToTeab_ ---> outlined bridged method (ab) of @objc __C.UITextField.text.getter : Swift.String?
288288
_T04test1SVyxGAA1RA2A1ZRzAA1Y2ZZRpzl1A_AhaGPWT ---> {C} associated type witness table accessor for A.ZZ : test.Y in <A where A: test.Z, A.ZZ: test.Y> test.S<A> : test.R in test
289-
_T0s24_UnicodeScalarExceptions33_0E4228093681F6920F0AB2E48B4F1C69LLVACycfC ---> Swift.(_UnicodeScalarExceptions in _0E4228093681F6920F0AB2E48B4F1C69).init() -> Swift.(_UnicodeScalarExceptions in _0E4228093681F6920F0AB2E48B4F1C69)
289+
_T0s24_UnicodeScalarExceptions33_0E4228093681F6920F0AB2E48B4F1C69LLVACycfC ---> {T:_T0s24_UnicodeScalarExceptions33_0E4228093681F6920F0AB2E48B4F1C69LLVACycfc} Swift.(_UnicodeScalarExceptions in _0E4228093681F6920F0AB2E48B4F1C69).init() -> Swift.(_UnicodeScalarExceptions in _0E4228093681F6920F0AB2E48B4F1C69)
290290
_T0D ---> _T0D
291291
_T0s18EnumeratedIteratorVyxGs8Sequencess0B8ProtocolRzlsADP5splitSay03SubC0QzGSi9maxSplits_Sb25omittingEmptySubsequencesSb7ElementQzKc14whereSeparatortKFTW ---> {T:} protocol witness for Swift.Sequence.split(maxSplits: Swift.Int, omittingEmptySubsequences: Swift.Bool, whereSeparator: (A.Element) throws -> Swift.Bool) throws -> [A.SubSequence] in conformance <A where A: Swift.IteratorProtocol> Swift.EnumeratedIterator<A> : Swift.Sequence in Swift
292292
_T0s3SetVyxGs10CollectiotySivm ---> _T0s3SetVyxGs10CollectiotySivm
@@ -334,4 +334,5 @@ $S18resilient_protocol21ResilientBaseProtocolTL ---> protocol requirements base
334334
$S1t1PP10AssocType2_AA1QTn ---> associated conformance descriptor for t.P.AssocType2: t.Q
335335
$S1t1PP10AssocType2_AA1QTN ---> default associated conformance accessor for t.P.AssocType2: t.Q
336336
$sSD5IndexVy__GD ---> $sSD5IndexVy__GD
337+
$s4test3StrCACycfC ---> {T:$s4test3StrCACycfc} test.Str.__allocating_init() -> test.Str
337338

0 commit comments

Comments
 (0)