]> granicus.if.org Git - clang/commitdiff
ir-gen support for nonfragile abi's synthesized ivars.
authorFariborz Jahanian <fjahanian@apple.com>
Tue, 31 Mar 2009 18:11:23 +0000 (18:11 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Tue, 31 Mar 2009 18:11:23 +0000 (18:11 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@68122 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/ASTContext.cpp
lib/CodeGen/CGObjCMac.cpp
test/CodeGenObjC/synthesize_ivar.m [new file with mode: 0644]

index 95c3c5fcaf33dc55616760b4c4801db1f006c4cb..422988d05d078f583b36894d6016fb96825ae6db 100644 (file)
@@ -705,6 +705,12 @@ ASTContext::getASTObjCInterfaceLayout(const ObjCInterfaceDecl *D) {
     const ObjCIvarDecl* Ivar = (*IVI);
     NewEntry->LayoutField(Ivar, i++, false, StructPacking, *this);
   }
+  // Also synthesized ivars
+  for (ObjCInterfaceDecl::prop_iterator I = D->prop_begin(),
+       E = D->prop_end(); I != E; ++I) {
+    if (ObjCIvarDecl *Ivar = (*I)->getPropertyIvarDecl())
+      NewEntry->LayoutField(Ivar, i++, false, StructPacking, *this);
+  }
 
   // Finally, round the size of the total struct up to the alignment of the
   // struct itself.
index 1354c4cf9e0cfb90ba6a8321136f73a7f92a8245..75cf4e76abad8499ce7ec2284aab223ae39489e0 100644 (file)
@@ -1673,6 +1673,12 @@ static int countInheritedIvars(const ObjCInterfaceDecl *OI) {
   for (ObjCInterfaceDecl::ivar_iterator I = OI->ivar_begin(),
        E = OI->ivar_end(); I != E; ++I)
     ++count;
+  // look into properties.
+  for (ObjCInterfaceDecl::prop_iterator I = OI->prop_begin(),
+       E = OI->prop_end(); I != E; ++I) {
+    if ((*I)->getPropertyIvarDecl())
+      ++count;
+  }
   return count;
 }
 
@@ -4559,13 +4565,20 @@ llvm::Constant *CGObjCNonFragileABIMac::EmitIvarList(
   
   RecordDecl::field_iterator i,p;
   const RecordDecl *RD = GetFirstIvarInRecord(OID, i,p);
-  ObjCInterfaceDecl::ivar_iterator I = OID->ivar_begin();
-  
+  // collect declared and synthesized ivars in a small vector.
+  llvm::SmallVector<ObjCIvarDecl*, 16> OIvars;
+  for (ObjCInterfaceDecl::ivar_iterator I = OID->ivar_begin(),
+       E = OID->ivar_end(); I != E; ++I) 
+     OIvars.push_back(*I);
+  for (ObjCInterfaceDecl::prop_iterator I = OID->prop_begin(),
+       E = OID->prop_end(); I != E; ++I)
+    if (ObjCIvarDecl *IV = (*I)->getPropertyIvarDecl())
+      OIvars.push_back(IV);
+  unsigned iv = 0;
   for (RecordDecl::field_iterator e = RD->field_end(); i != e; ++i) {
     FieldDecl *Field = *i;
     uint64_t offset = GetIvarBaseOffset(Layout, Field);
-    const ObjCIvarDecl *ivarDecl = *I++;
-    Ivar[0] = EmitIvarOffsetVar(ID->getClassInterface(), ivarDecl, offset);
+    Ivar[0] = EmitIvarOffsetVar(ID->getClassInterface(), OIvars[iv++], offset);
     if (Field->getIdentifier())
       Ivar[1] = GetMethodVarName(Field->getIdentifier());
     else
diff --git a/test/CodeGenObjC/synthesize_ivar.m b/test/CodeGenObjC/synthesize_ivar.m
new file mode 100644 (file)
index 0000000..fcc67f8
--- /dev/null
@@ -0,0 +1,14 @@
+// RUN: clang-cc -arch x86_64 -emit-llvm -o %t %s
+
+@interface I
+{
+}
+@property int IP;
+@end
+
+@implementation I
+@synthesize IP;
+- (int) Meth {
+   return IP;
+}
+@end