[SourceKit] Don't report the ObjC runtime name without @objc(Name)

We used to compute the mangled name in other cases, but document structure is
a syntactic request and can't guarantee that the class/protocol we're getting
the mangled name of is valid in any way so it often breaks assumptions in the
mangler and causes it to crash. It's not clear if the runtime_name is actually
being used anymore, so this change restricts reporting it to just the cases
where we don't need to mangle.

rdar://problem/40956377
This commit is contained in:
Nathan Hawes
2020-02-14 11:40:09 -08:00
parent d5cb71a1af
commit 2420b6d28b
15 changed files with 70 additions and 119 deletions

View File

@@ -1334,30 +1334,14 @@ public:
}
StringRef getObjCRuntimeName(const Decl *D, SmallString<64> &Buf) {
if (!D)
return StringRef();
if (!isa<ClassDecl>(D) && !isa<ProtocolDecl>(D))
return StringRef();
auto *VD = cast<ValueDecl>(D);
if (!VD->hasName() || (VD->hasInterfaceType() && VD->isInvalid()))
return StringRef();
auto ident = VD->getBaseName().getIdentifier().str();
if (ident.empty() || Mangle::isDigit(ident.front()))
return StringRef();
// We don't support getting the runtime name for nested classes.
// This would require typechecking or at least name lookup, if the nested
// class is in an extension.
if (!D->getDeclContext()->isModuleScopeContext())
return StringRef();
if (auto ClassD = dyn_cast<ClassDecl>(D)) {
// We don't vend the runtime name for generic classes for now.
if (ClassD->getGenericParams())
return StringRef();
return ClassD->getObjCRuntimeName(Buf);
// We only report runtime name for classes and protocols with an explicitly
// defined ObjC name, i.e. those that have @objc("SomeName")
if (D && (isa<ClassDecl>(D) || isa<ProtocolDecl>(D))) {
auto *ObjCNameAttr = D->getAttrs().getAttribute<ObjCAttr>();
if (ObjCNameAttr && ObjCNameAttr->hasName())
return ObjCNameAttr->getName()->getString(Buf);
}
return cast<ProtocolDecl>(D)->getObjCRuntimeName(Buf);
return StringRef();
}
StringRef getObjCSelectorName(const Decl *D, SmallString<64> &Buf) {