Skip to content

Commit 305e024

Browse files
committed
[lldb] Fix dynamic type resolution for ObjC protocol existentials
An existential whose protocol type is an Objective-C protocol is not passed in an existential container, but as a plain old instance pointer. This patch dynamic type resolution failing for those types. rdar://144028358 (cherry picked from commit 419a0bb)
1 parent b1eb50d commit 305e024

File tree

1 file changed

+42
-4
lines changed

1 file changed

+42
-4
lines changed

lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwiftTypeRef.cpp

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1652,6 +1652,47 @@ swift::Demangle::NodePointer TypeSystemSwiftTypeRef::GetDemangleTreeForPrinting(
16521652
return GetNodeForPrintingImpl(dem, node, flavor, resolve_objc_module);
16531653
}
16541654

1655+
static bool ProtocolCompositionContainsSingleObjcProtocol(
1656+
swift::Demangle::NodePointer node) {
1657+
// Kind=ProtocolList
1658+
// Kind=TypeList
1659+
// Kind=Type
1660+
// Kind=Protocol
1661+
// Kind=Module, text="__C"
1662+
// Kind=Identifier, text="SomeIdentifier"
1663+
if (node->getKind() != Node::Kind::ProtocolList)
1664+
return false;
1665+
NodePointer type_list = node->getFirstChild();
1666+
if (type_list->getKind() != Node::Kind::TypeList ||
1667+
type_list->getNumChildren() != 1)
1668+
return false;
1669+
NodePointer type = type_list->getFirstChild();
1670+
return Contains(type, Node::Kind::Module, swift::MANGLING_MODULE_OBJC);
1671+
}
1672+
1673+
/// Determine wether this demangle tree contains a node of kind \c kind and with
1674+
/// text \c text (if provided).
1675+
static bool Contains(swift::Demangle::NodePointer node,
1676+
swift::Demangle::Node::Kind kind,
1677+
llvm::StringRef text = "") {
1678+
if (!node)
1679+
return false;
1680+
1681+
if (node->getKind() == kind) {
1682+
if (text.empty())
1683+
return true;
1684+
if (!node->hasText())
1685+
return false;
1686+
return node->getText() == text;
1687+
}
1688+
1689+
for (swift::Demangle::NodePointer child : *node)
1690+
if (Contains(child, kind, text))
1691+
return true;
1692+
1693+
return false;
1694+
}
1695+
16551696
static bool ProtocolCompositionContainsSingleObjcProtocol(
16561697
swift::Demangle::NodePointer node) {
16571698
// Kind=ProtocolList
@@ -1667,10 +1708,7 @@ static bool ProtocolCompositionContainsSingleObjcProtocol(
16671708
type_list->getNumChildren() != 1)
16681709
return false;
16691710
NodePointer type = type_list->getFirstChild();
1670-
return swift_demangle::FindIf(type, [](NodePointer node) {
1671-
return node->getKind() == Node::Kind::Module && node->hasText() &&
1672-
node->getText() == swift::MANGLING_MODULE_OBJC;
1673-
});
1711+
return Contains(type, Node::Kind::Module, swift::MANGLING_MODULE_OBJC);
16741712
}
16751713

16761714
/// Determine wether this demangle tree contains a generic type parameter.

0 commit comments

Comments
 (0)