objective-C++ IRGen: property reference as an
lvalue when performing a derived-to-base conversion.
Fixes radar 7501812. Added an executable test to
llvm-test suite.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@106247 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/CGExpr.cpp b/lib/CodeGen/CGExpr.cpp
index aab5409..8655a66 100644
--- a/lib/CodeGen/CGExpr.cpp
+++ b/lib/CodeGen/CGExpr.cpp
@@ -1818,10 +1818,18 @@
cast<CXXRecordDecl>(DerivedClassTy->getDecl());
LValue LV = EmitLValue(E->getSubExpr());
+ llvm::Value *This;
+ if (LV.isPropertyRef()) {
+ RValue RV = EmitLoadOfPropertyRefLValue(LV, E->getSubExpr()->getType());
+ assert (!RV.isScalar() && "EmitCastLValue");
+ This = RV.getAggregateAddr();
+ }
+ else
+ This = LV.getAddress();
// Perform the derived-to-base conversion
llvm::Value *Base =
- GetAddressOfBaseClass(LV.getAddress(), DerivedClassDecl,
+ GetAddressOfBaseClass(This, DerivedClassDecl,
E->getBasePath(), /*NullCheckValue=*/false);
return LValue::MakeAddr(Base, MakeQualifiers(E->getType()));
diff --git a/test/CodeGenObjCXX/property-derived-to-base-conv.mm b/test/CodeGenObjCXX/property-derived-to-base-conv.mm
new file mode 100644
index 0000000..ada1202
--- /dev/null
+++ b/test/CodeGenObjCXX/property-derived-to-base-conv.mm
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -fobjc-gc -triple x86_64-apple-darwin10 -emit-llvm -o - %s
+// rdar: // 7501812
+
+struct A { int member; };
+struct B : A { };
+
+@interface BInt {
+@private
+ B *b;
+}
+- (B)value;
+- (void)setValue : (B) arg;
+@property B value;
+@end
+
+void g(BInt *bint) {
+ bint.value.member = 17;
+}
+