Code Gen support for Getter/Setter synthesis of 
C++ object properties. (still radar 7468090).


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@103182 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/CGObjC.cpp b/lib/CodeGen/CGObjC.cpp
index 7ea075d..b3e9dc5 100644
--- a/lib/CodeGen/CGObjC.cpp
+++ b/lib/CodeGen/CGObjC.cpp
@@ -205,8 +205,9 @@
                                            Types.ConvertType(PD->getType())));
     EmitReturnOfRValue(RV, PD->getType());
   } else {
-    LValue LV = EmitLValueForIvar(TypeOfSelfObject(), LoadObjCSelf(), Ivar, 0);
     if (Ivar->getType()->isAnyComplexType()) {
+      LValue LV = EmitLValueForIvar(TypeOfSelfObject(), LoadObjCSelf(), 
+                                    Ivar, 0);
       ComplexPairTy Pair = LoadComplexFromAddr(LV.getAddress(),
                                                LV.isVolatileQualified());
       StoreComplexToAddr(Pair, ReturnValue, LV.isVolatileQualified());
@@ -216,6 +217,8 @@
       if ((IsAtomic || (IsStrong = IvarTypeWithAggrGCObjects(Ivar->getType())))
           && CurFnInfo->getReturnInfo().getKind() == ABIArgInfo::Indirect
           && CGM.getObjCRuntime().GetCopyStructFunction()) {
+        LValue LV = EmitLValueForIvar(TypeOfSelfObject(), LoadObjCSelf(), 
+                                      Ivar, 0);
         llvm::Value *GetCopyStructFn =
           CGM.getObjCRuntime().GetCopyStructFunction();
         CodeGenTypes &Types = CGM.getTypes();
@@ -248,9 +251,22 @@
                                        FunctionType::ExtInfo()),
                  GetCopyStructFn, ReturnValueSlot(), Args);
       }
-      else
-        EmitAggregateCopy(ReturnValue, LV.getAddress(), Ivar->getType());
+      else {
+        if (PID->getGetterCXXConstructor()) {
+          ReturnStmt *Stmt = 
+            new (getContext()) ReturnStmt(SourceLocation(), 
+                                          PID->getGetterCXXConstructor());
+          EmitReturnStmt(*Stmt);
+        }
+        else {
+          LValue LV = EmitLValueForIvar(TypeOfSelfObject(), LoadObjCSelf(), 
+                                        Ivar, 0);
+          EmitAggregateCopy(ReturnValue, LV.getAddress(), Ivar->getType());
+        }
+      }
     } else {
+      LValue LV = EmitLValueForIvar(TypeOfSelfObject(), LoadObjCSelf(), 
+                                    Ivar, 0);
       CodeGenTypes &Types = CGM.getTypes();
       RValue RV = EmitLoadOfLValue(LV, Ivar->getType());
       RV = RValue::get(Builder.CreateBitCast(RV.getScalarVal(),
@@ -362,6 +378,10 @@
     EmitCall(Types.getFunctionInfo(getContext().VoidTy, Args,
                                    FunctionType::ExtInfo()),
              GetCopyStructFn, ReturnValueSlot(), Args);
+  } else if (PID->getSetterCXXAssignment()) {
+    EmitAnyExpr(PID->getSetterCXXAssignment(), (llvm::Value *)0, false, true,
+                false);
+                
   } else {
     // FIXME: Find a clean way to avoid AST node creation.
     SourceLocation Loc = PD->getLocation();