objc2's ir-gen for nonfragile ivar access.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@63578 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/CGObjC.cpp b/lib/CodeGen/CGObjC.cpp
index 9dc45ef..3ebee12 100644
--- a/lib/CodeGen/CGObjC.cpp
+++ b/lib/CodeGen/CGObjC.cpp
@@ -194,7 +194,8 @@
   } else {
     FieldDecl *Field = 
       IMP->getClassInterface()->lookupFieldDeclForIvar(getContext(), Ivar);
-    LValue LV = EmitLValueForIvar(LoadObjCSelf(), Ivar, Field, 0);
+    LValue LV = EmitLValueForIvar(TypeOfSelfObject(),
+                                  LoadObjCSelf(), Ivar, Field, 0);
     if (hasAggregateLLVMType(Ivar->getType())) {
       EmitAggregateCopy(ReturnValue, LV.getAddress(), Ivar->getType());
     }
@@ -294,6 +295,14 @@
   return Builder.CreateLoad(LocalDeclMap[OMD->getSelfDecl()], "self");
 }
 
+QualType CodeGenFunction::TypeOfSelfObject() {
+  const ObjCMethodDecl *OMD = cast<ObjCMethodDecl>(CurFuncDecl);
+  ImplicitParamDecl *selfDecl = OMD->getSelfDecl();
+  const PointerType *PTy = 
+    cast<PointerType>(getContext().getCanonicalType(selfDecl->getType()));
+  return PTy->getPointeeType();
+}
+
 RValue CodeGenFunction::EmitObjCPropertyGet(const Expr *Exp) {
   // FIXME: Split it into two separate routines.
   if (const ObjCPropertyRefExpr *E = dyn_cast<ObjCPropertyRefExpr>(Exp)) {