ir-gen support for nonfragile abi's synthesized ivars.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@68122 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp
index 95c3c5f..422988d 100644
--- a/lib/AST/ASTContext.cpp
+++ b/lib/AST/ASTContext.cpp
@@ -705,6 +705,12 @@
     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.
diff --git a/lib/CodeGen/CGObjCMac.cpp b/lib/CodeGen/CGObjCMac.cpp
index 1354c4c..75cf4e7 100644
--- a/lib/CodeGen/CGObjCMac.cpp
+++ b/lib/CodeGen/CGObjCMac.cpp
@@ -1673,6 +1673,12 @@
   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 @@
   
   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
index 0000000..fcc67f8
--- /dev/null
+++ b/test/CodeGenObjC/synthesize_ivar.m
@@ -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