Skip to content

demangler: classify allocating init functions as thunks #19912

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/swift/Demangling/Demangle.h
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ class Context {
/// Returns true if the mangledName refers to a thunk function.
///
/// Thunk functions are either (ObjC) partial apply forwarder, swift-as-ObjC
/// or ObjC-as-swift thunks.
/// or ObjC-as-swift thunks or allocating init functions.
bool isThunkSymbol(llvm::StringRef MangledName);

/// Returns the mangled name of the target of a thunk.
Expand Down
10 changes: 9 additions & 1 deletion lib/Demangling/Context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ bool Context::isThunkSymbol(llvm::StringRef MangledName) {
MangledName.endswith("TO") || // ObjC-as-swift thunk
MangledName.endswith("TR") || // reabstraction thunk helper function
MangledName.endswith("Tr") || // reabstraction thunk
MangledName.endswith("TW")) { // protocol witness thunk
MangledName.endswith("TW") || // protocol witness thunk
MangledName.endswith("fC")) { // allocating constructor

// To avoid false positives, we need to fully demangle the symbol.
NodePointer Nd = D->demangleSymbol(MangledName);
Expand All @@ -93,6 +94,7 @@ bool Context::isThunkSymbol(llvm::StringRef MangledName) {
case Node::Kind::ReabstractionThunkHelper:
case Node::Kind::ReabstractionThunk:
case Node::Kind::ProtocolWitness:
case Node::Kind::Allocator:
return true;
default:
break;
Expand Down Expand Up @@ -125,6 +127,12 @@ std::string Context::getThunkTarget(llvm::StringRef MangledName) {
MangledName.endswith("TW") )
return std::string();

if (MangledName.endswith("fC")) {
std::string target = MangledName.str();
target[target.size() - 1] = 'c';
return target;
}

return MangledName.substr(0, MangledName.size() - 2).str();
}
// Old mangling.
Expand Down
3 changes: 2 additions & 1 deletion test/Demangle/Inputs/manglings.txt
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ _T03nix6testitSaySiGyFTv0_ ---> outlined variable #1 of nix.testit() -> [Swift.I
_T0So11UITextFieldC4textSSSgvgToTepb_ ---> outlined bridged method (pb) of @objc __C.UITextField.text.getter : Swift.String?
_T0So11UITextFieldC4textSSSgvgToTeab_ ---> outlined bridged method (ab) of @objc __C.UITextField.text.getter : Swift.String?
_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
_T0s24_UnicodeScalarExceptions33_0E4228093681F6920F0AB2E48B4F1C69LLVACycfC ---> Swift.(_UnicodeScalarExceptions in _0E4228093681F6920F0AB2E48B4F1C69).init() -> Swift.(_UnicodeScalarExceptions in _0E4228093681F6920F0AB2E48B4F1C69)
_T0s24_UnicodeScalarExceptions33_0E4228093681F6920F0AB2E48B4F1C69LLVACycfC ---> {T:_T0s24_UnicodeScalarExceptions33_0E4228093681F6920F0AB2E48B4F1C69LLVACycfc} Swift.(_UnicodeScalarExceptions in _0E4228093681F6920F0AB2E48B4F1C69).init() -> Swift.(_UnicodeScalarExceptions in _0E4228093681F6920F0AB2E48B4F1C69)
_T0D ---> _T0D
_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
_T0s3SetVyxGs10CollectiotySivm ---> _T0s3SetVyxGs10CollectiotySivm
Expand Down Expand Up @@ -334,4 +334,5 @@ $S18resilient_protocol21ResilientBaseProtocolTL ---> protocol requirements base
$S1t1PP10AssocType2_AA1QTn ---> associated conformance descriptor for t.P.AssocType2: t.Q
$S1t1PP10AssocType2_AA1QTN ---> default associated conformance accessor for t.P.AssocType2: t.Q
$sSD5IndexVy__GD ---> $sSD5IndexVy__GD
$s4test3StrCACycfC ---> {T:$s4test3StrCACycfc} test.Str.__allocating_init() -> test.Str