Patch to implement code gen. use of compound assignent on
properties of complex type. Radar 7351147.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@99299 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/CGExprComplex.cpp b/lib/CodeGen/CGExprComplex.cpp
index 5915340..ee104b7 100644
--- a/lib/CodeGen/CGExprComplex.cpp
+++ b/lib/CodeGen/CGExprComplex.cpp
@@ -522,13 +522,20 @@
   // scalar.
   OpInfo.Ty = E->getComputationResultType();
   OpInfo.RHS = EmitCast(E->getRHS(), OpInfo.Ty);
-
+  
   LValue LHSLV = CGF.EmitLValue(E->getLHS());
-
-
+  assert(!LHSLV.isKVCRef() && 
+         "setter/getter access of complex using property syntax NYI");
   // We know the LHS is a complex lvalue.
-  OpInfo.LHS=EmitLoadOfComplex(LHSLV.getAddress(), LHSLV.isVolatileQualified());
-  OpInfo.LHS=EmitComplexToComplexCast(OpInfo.LHS, LHSTy, OpInfo.Ty);
+  ComplexPairTy LHSComplexPair;
+  if (LHSLV.isPropertyRef())
+    LHSComplexPair = 
+      CGF.EmitObjCPropertyGet(LHSLV.getPropertyRefExpr()).getComplexVal();
+  else
+    LHSComplexPair = EmitLoadOfComplex(LHSLV.getAddress(), 
+                                       LHSLV.isVolatileQualified());
+  
+  OpInfo.LHS=EmitComplexToComplexCast(LHSComplexPair, LHSTy, OpInfo.Ty);
 
   // Expand the binary operator.
   ComplexPairTy Result = (this->*Func)(OpInfo);
@@ -537,12 +544,18 @@
   Result = EmitComplexToComplexCast(Result, OpInfo.Ty, LHSTy);
 
   // Store the result value into the LHS lvalue.
-  EmitStoreOfComplex(Result, LHSLV.getAddress(), LHSLV.isVolatileQualified());
+  if (LHSLV.isPropertyRef())
+    CGF.EmitObjCPropertySet(LHSLV.getPropertyRefExpr(), 
+                            RValue::getComplex(Result));
+  else
+    EmitStoreOfComplex(Result, LHSLV.getAddress(), LHSLV.isVolatileQualified());
   // And now return the LHS
   IgnoreReal = ignreal;
   IgnoreImag = ignimag;
   IgnoreRealAssign = ignreal;
   IgnoreImagAssign = ignimag;
+  if (LHSLV.isPropertyRef())
+    return CGF.EmitObjCPropertyGet(LHSLV.getPropertyRefExpr()).getComplexVal();
   return EmitLoadOfComplex(LHSLV.getAddress(), LHSLV.isVolatileQualified());
 }
 
diff --git a/test/CodeGenObjC/complex-property.m b/test/CodeGenObjC/complex-property.m
new file mode 100644
index 0000000..6d7cda1
--- /dev/null
+++ b/test/CodeGenObjC/complex-property.m
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10  -emit-llvm -o - %s | FileCheck -check-prefix LP64 %s
+// rdar: // 7351147
+
+@interface A
+@property __complex int COMPLEX_PROP;
+@end
+
+void f0(A *a) {  
+  _Complex int a1 = 25 + 10i;
+  a.COMPLEX_PROP += a1;
+}
+
+// CHECK-LP64: internal global [13 x i8] c"COMPLEX_PROP
+// CHECK-LP64: internal global [17 x i8] c"setCOMPLEX_PROP