[cfe-commits] r128551 - in /cfe/trunk: include/clang/AST/ExprObjC.h lib/CodeGen/CGExpr.cpp lib/CodeGen/CGExprAgg.cpp lib/CodeGen/CGObjC.cpp test/CodeGenObjCXX/property-reference.mm

Fariborz Jahanian fjahanian at apple.com
Wed Mar 30 09:11:20 PDT 2011


Author: fjahanian
Date: Wed Mar 30 11:11:20 2011
New Revision: 128551

URL: http://llvm.org/viewvc/llvm-project?rev=128551&view=rev
Log:
Fix IRGen issues related to using property-dot syntax
for prperty reference types. // rdar://9208606.


Added:
    cfe/trunk/test/CodeGenObjCXX/property-reference.mm
Modified:
    cfe/trunk/include/clang/AST/ExprObjC.h
    cfe/trunk/lib/CodeGen/CGExpr.cpp
    cfe/trunk/lib/CodeGen/CGExprAgg.cpp
    cfe/trunk/lib/CodeGen/CGObjC.cpp

Modified: cfe/trunk/include/clang/AST/ExprObjC.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ExprObjC.h?rev=128551&r1=128550&r2=128551&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/ExprObjC.h (original)
+++ cfe/trunk/include/clang/AST/ExprObjC.h Wed Mar 30 11:11:20 2011
@@ -337,6 +337,39 @@
   QualType getSuperReceiverType() const { 
     return QualType(Receiver.get<const Type*>(), 0); 
   }
+  QualType getGetterResultType() const {
+    QualType ResultType;
+    if (isExplicitProperty()) {
+      const ObjCPropertyDecl *PDecl = getExplicitProperty();
+      if (const ObjCMethodDecl *Getter = PDecl->getGetterMethodDecl())
+        ResultType = Getter->getResultType();
+      else
+        ResultType = getType();
+    } else {
+      const ObjCMethodDecl *Getter = getImplicitPropertyGetter();
+      ResultType = Getter->getResultType(); // with reference!
+    }
+    return ResultType;
+  }
+  
+  QualType getSetterArgType() const {
+    QualType ArgType;
+    if (isImplicitProperty()) {
+      const ObjCMethodDecl *Setter = getImplicitPropertySetter();
+      ObjCMethodDecl::param_iterator P = Setter->param_begin(); 
+      ArgType = (*P)->getType();
+    } else {
+      if (ObjCPropertyDecl *PDecl = getExplicitProperty())
+        if (const ObjCMethodDecl *Setter = PDecl->getSetterMethodDecl()) {
+          ObjCMethodDecl::param_iterator P = Setter->param_begin(); 
+          ArgType = (*P)->getType();
+        }
+      if (ArgType.isNull())
+        ArgType = getType();
+    }
+    return ArgType;
+  }
+  
   ObjCInterfaceDecl *getClassReceiver() const {
     return Receiver.get<ObjCInterfaceDecl*>();
   }

Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=128551&r1=128550&r2=128551&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Wed Mar 30 11:11:20 2011
@@ -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();
     

Modified: cfe/trunk/lib/CodeGen/CGExprAgg.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprAgg.cpp?rev=128551&r1=128550&r2=128551&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprAgg.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprAgg.cpp Wed Mar 30 11:11:20 2011
@@ -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())

Modified: cfe/trunk/lib/CodeGen/CGObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjC.cpp?rev=128551&r1=128550&r2=128551&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjC.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjC.cpp Wed Mar 30 11:11:20 2011
@@ -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()) {

Added: cfe/trunk/test/CodeGenObjCXX/property-reference.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjCXX/property-reference.mm?rev=128551&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenObjCXX/property-reference.mm (added)
+++ cfe/trunk/test/CodeGenObjCXX/property-reference.mm Wed Mar 30 11:11:20 2011
@@ -0,0 +1,34 @@
+// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -emit-llvm -o - | FileCheck %s
+// rdar://9208606
+
+struct MyStruct
+{
+	int x;
+	int y;
+	int z;
+};
+
+ at interface MyClass
+{
+	MyStruct _foo;
+}
+
+ at property (assign, readwrite) const MyStruct& foo;
+
+- (const MyStruct&) foo;
+- (void) setFoo:(const MyStruct&)inFoo;
+ at end
+
+int main()
+{
+	MyClass* myClass;
+	MyStruct myStruct;
+
+	myClass.foo = myStruct;
+
+	const MyStruct& currentMyStruct = myClass.foo;   
+	return 0;
+}
+
+// CHECK: [[C:%.*]] = call %struct.MyStruct* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend
+// CHECK:   store %struct.MyStruct* [[C]], %struct.MyStruct** [[D:%.*]]





More information about the cfe-commits mailing list