Fix IRGen issues related to using property-dot syntax
for prperty reference types. // rdar://9208606.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@128551 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/CGExpr.cpp b/lib/CodeGen/CGExpr.cpp
index 6a7be0f..ab88a38 100644
--- a/lib/CodeGen/CGExpr.cpp
+++ b/lib/CodeGen/CGExpr.cpp
@@ -216,10 +216,19 @@
                                        InitializedDecl);
   }
 
+  if (const ObjCPropertyRefExpr *PRE = 
+      dyn_cast<ObjCPropertyRefExpr>(E->IgnoreParenImpCasts()))
+    if (PRE->getGetterResultType()->isReferenceType())
+      E = PRE;
+    
   RValue RV;
   if (E->isGLValue()) {
     // Emit the expression as an lvalue.
     LValue LV = CGF.EmitLValue(E);
+    if (LV.isPropertyRef()) {
+      RV = CGF.EmitLoadOfPropertyRefLValue(LV);
+      return RV.getScalarVal();
+    }
     if (LV.isSimple())
       return LV.getAddress();
     
diff --git a/lib/CodeGen/CGExprAgg.cpp b/lib/CodeGen/CGExprAgg.cpp
index f992dc7..eb64996 100644
--- a/lib/CodeGen/CGExprAgg.cpp
+++ b/lib/CodeGen/CGExprAgg.cpp
@@ -403,9 +403,17 @@
   // We have to special case property setters, otherwise we must have
   // a simple lvalue (no aggregates inside vectors, bitfields).
   if (LHS.isPropertyRef()) {
-    AggValueSlot Slot = EnsureSlot(E->getRHS()->getType());
-    CGF.EmitAggExpr(E->getRHS(), Slot);
-    CGF.EmitStoreThroughPropertyRefLValue(Slot.asRValue(), LHS);
+    const ObjCPropertyRefExpr *RE = LHS.getPropertyRefExpr();
+    QualType ArgType = RE->getSetterArgType();
+    RValue Src;
+    if (ArgType->isReferenceType())
+      Src = CGF.EmitReferenceBindingToExpr(E->getRHS(), 0);
+    else {
+      AggValueSlot Slot = EnsureSlot(E->getRHS()->getType());
+      CGF.EmitAggExpr(E->getRHS(), Slot);
+      Src = Slot.asRValue();
+    }
+    CGF.EmitStoreThroughPropertyRefLValue(Src, LHS);
   } else {
     bool GCollection = false;
     if (CGF.getContext().getLangOptions().getGCMode())
diff --git a/lib/CodeGen/CGObjC.cpp b/lib/CodeGen/CGObjC.cpp
index 99b8b57..ac4e763 100644
--- a/lib/CodeGen/CGObjC.cpp
+++ b/lib/CodeGen/CGObjC.cpp
@@ -651,16 +651,14 @@
 RValue CodeGenFunction::EmitLoadOfPropertyRefLValue(LValue LV,
                                                     ReturnValueSlot Return) {
   const ObjCPropertyRefExpr *E = LV.getPropertyRefExpr();
-  QualType ResultType;
+  QualType ResultType = E->getGetterResultType();
   Selector S;
   if (E->isExplicitProperty()) {
     const ObjCPropertyDecl *Property = E->getExplicitProperty();
     S = Property->getGetterName();
-    ResultType = E->getType();
   } else {
     const ObjCMethodDecl *Getter = E->getImplicitPropertyGetter();
     S = Getter->getSelector();
-    ResultType = Getter->getResultType(); // with reference!
   }
 
   llvm::Value *Receiver = LV.getPropertyRefBaseAddr();
@@ -681,14 +679,8 @@
                                                         LValue Dst) {
   const ObjCPropertyRefExpr *E = Dst.getPropertyRefExpr();
   Selector S = E->getSetterSelector();
-  QualType ArgType;
-  if (E->isImplicitProperty()) {
-    const ObjCMethodDecl *Setter = E->getImplicitPropertySetter();
-    ObjCMethodDecl::param_iterator P = Setter->param_begin(); 
-    ArgType = (*P)->getType();
-  } else {
-    ArgType = E->getType();
-  }
+  QualType ArgType = E->getSetterArgType();
+  
   // FIXME. Other than scalars, AST is not adequate for setter and
   // getter type mismatches which require conversion.
   if (Src.isScalar()) {