Fix rdar://6804402 - crash on objc implementations declared with
@class but no implementation. This was broken in all 3 runtime
impls.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@69512 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/CGObjCMac.cpp b/lib/CodeGen/CGObjCMac.cpp
index 0d6dd6a..238f7c5 100644
--- a/lib/CodeGen/CGObjCMac.cpp
+++ b/lib/CodeGen/CGObjCMac.cpp
@@ -1484,7 +1484,11 @@
EmitProtocolList("\01L_OBJC_CLASS_PROTOCOLS_" + ID->getNameAsString(),
Interface->protocol_begin(),
Interface->protocol_end());
- const llvm::Type *InterfaceTy =
+ const llvm::Type *InterfaceTy;
+ if (Interface->isForwardDecl())
+ InterfaceTy = llvm::StructType::get(NULL, NULL);
+ else
+ InterfaceTy =
CGM.getTypes().ConvertType(CGM.getContext().getObjCInterfaceType(Interface));
unsigned Flags = eClassFlags_Factory;
unsigned Size = CGM.getTargetData().getTypePaddedSize(InterfaceTy);
@@ -2562,10 +2566,16 @@
/// interface declaration.
const llvm::StructLayout *CGObjCCommonMac::GetInterfaceDeclStructLayout(
const ObjCInterfaceDecl *OID) const {
- const llvm::Type *InterfaceTy =
- CGM.getTypes().ConvertType(
- CGM.getContext().getObjCInterfaceType(
- const_cast<ObjCInterfaceDecl*>(OID)));
+ const llvm::Type *InterfaceTy;
+
+ if (OID->isForwardDecl()) {
+ InterfaceTy = llvm::StructType::get(NULL, NULL);
+ } else {
+ QualType T = CGM.getContext().getObjCInterfaceType(
+ const_cast<ObjCInterfaceDecl*>(OID));
+ InterfaceTy = CGM.getTypes().ConvertType(T);
+ }
+
const llvm::StructLayout *Layout =
CGM.getTargetData().getStructLayout(cast<llvm::StructType>(InterfaceTy));
return Layout;
@@ -4263,8 +4273,7 @@
if (!ID->getClassInterface()->getSuperClass()) {
flags |= CLS_ROOT;
SuperClassGV = 0;
- }
- else {
+ } else {
// Has a root. Current class is not a root.
std::string RootClassName =
ID->getClassInterface()->getSuperClass()->getNameAsString();
@@ -4273,7 +4282,7 @@
// FIXME: Gross
InstanceStart = InstanceSize = 0;
if (ObjCInterfaceDecl *OID =
- const_cast<ObjCInterfaceDecl*>(ID->getClassInterface())) {
+ const_cast<ObjCInterfaceDecl*>(ID->getClassInterface())) {
// FIXME. Share this with the one in EmitIvarList.
const llvm::StructLayout *Layout = GetInterfaceDeclStructLayout(OID);