[cfe-commits] r69512 - in /cfe/trunk: lib/CodeGen/CGObjCGNU.cpp lib/CodeGen/CGObjCMac.cpp test/CodeGenObjC/class-type.m

Chris Lattner sabre at nondot.org
Sat Apr 18 23:02:29 PDT 2009


Author: lattner
Date: Sun Apr 19 01:02:28 2009
New Revision: 69512

URL: http://llvm.org/viewvc/llvm-project?rev=69512&view=rev
Log:
Fix rdar://6804402 - crash on objc implementations declared with
@class but no implementation.  This was broken in all 3 runtime
impls.


Modified:
    cfe/trunk/lib/CodeGen/CGObjCGNU.cpp
    cfe/trunk/lib/CodeGen/CGObjCMac.cpp
    cfe/trunk/test/CodeGenObjC/class-type.m

Modified: cfe/trunk/lib/CodeGen/CGObjCGNU.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCGNU.cpp?rev=69512&r1=69511&r2=69512&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjCGNU.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjCGNU.cpp Sun Apr 19 01:02:28 2009
@@ -739,8 +739,12 @@
   // Get the size of instances.  For runtimes that support late-bound instances
   // this should probably be something different (size just of instance
   // varaibles in this class, not superclasses?).
-  const llvm::Type *ObjTy =
-    CGM.getTypes().ConvertType(Context.getObjCInterfaceType(ClassDecl));
+  const llvm::Type *ObjTy;
+
+  if (ClassDecl->isForwardDecl())
+    ObjTy = llvm::StructType::get(NULL, NULL);
+  else
+    ObjTy = CGM.getTypes().ConvertType(Context.getObjCInterfaceType(ClassDecl));
   int instanceSize = CGM.getTargetData().getTypePaddedSize(ObjTy);
 
   // Collect information about instance variables.

Modified: cfe/trunk/lib/CodeGen/CGObjCMac.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCMac.cpp?rev=69512&r1=69511&r2=69512&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjCMac.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjCMac.cpp Sun Apr 19 01:02:28 2009
@@ -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);
     

Modified: cfe/trunk/test/CodeGenObjC/class-type.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/class-type.m?rev=69512&r1=69511&r2=69512&view=diff

==============================================================================
--- cfe/trunk/test/CodeGenObjC/class-type.m (original)
+++ cfe/trunk/test/CodeGenObjC/class-type.m Sun Apr 19 01:02:28 2009
@@ -1,4 +1,7 @@
-// RUN: clang-cc -triple x86_64-unknown-unknown -emit-llvm -o - %s
+// RUN: clang-cc -triple x86_64-unknown-unknown -emit-llvm -o - %s &&
+// RUN: clang-cc -triple i386-apple-darwin9 -emit-llvm -o - %s &&
+// RUN: clang-cc -triple x86_64-apple-darwin9 -emit-llvm -o - %s
+
 
 @interface I0 {
   struct { int a; } a;
@@ -22,3 +25,12 @@
 @end 
 
 
+// Implementations without interface declarations.
+// rdar://6804402
+ at class foo;
+ at implementation foo 
+ at end
+
+ at implementation bar
+ at end
+





More information about the cfe-commits mailing list