[cfe-commits] r139585 - in /cfe/trunk: lib/CodeGen/CGObjC.cpp test/CodeGenObjCXX/property-reference.mm
John McCall
rjmccall at apple.com
Mon Sep 12 23:00:03 PDT 2011
Author: rjmccall
Date: Tue Sep 13 01:00:03 2011
New Revision: 139585
URL: http://llvm.org/viewvc/llvm-project?rev=139585&view=rev
Log:
Handle reference properties correctly in the trivial-getter check.
Modified:
cfe/trunk/lib/CodeGen/CGObjC.cpp
cfe/trunk/test/CodeGenObjCXX/property-reference.mm
Modified: cfe/trunk/lib/CodeGen/CGObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjC.cpp?rev=139585&r1=139584&r2=139585&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjC.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjC.cpp Tue Sep 13 01:00:03 2011
@@ -564,13 +564,19 @@
FinishFunction();
}
-static bool hasTrivialGetExpr(const ObjCPropertyImplDecl *PID) {
- const Expr *getter = PID->getGetterCXXConstructor();
+static bool hasTrivialGetExpr(const ObjCPropertyImplDecl *propImpl) {
+ const Expr *getter = propImpl->getGetterCXXConstructor();
if (!getter) return true;
// Sema only makes only of these when the ivar has a C++ class type,
// so the form is pretty constrained.
+ // If the property has a reference type, we might just be binding a
+ // reference, in which case the result will be a gl-value. We should
+ // treat this as a non-trivial operation.
+ if (getter->isGLValue())
+ return false;
+
// If we selected a trivial copy-constructor, we're okay.
if (const CXXConstructExpr *construct = dyn_cast<CXXConstructExpr>(getter))
return (construct->getConstructor()->isTrivial());
Modified: cfe/trunk/test/CodeGenObjCXX/property-reference.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjCXX/property-reference.mm?rev=139585&r1=139584&r2=139585&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenObjCXX/property-reference.mm (original)
+++ cfe/trunk/test/CodeGenObjCXX/property-reference.mm Tue Sep 13 01:00:03 2011
@@ -1,16 +1,14 @@
// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -emit-llvm -o - | FileCheck %s
// rdar://9208606
-struct MyStruct
-{
- int x;
- int y;
- int z;
+struct MyStruct {
+ int x;
+ int y;
+ int z;
};
- at interface MyClass
-{
- MyStruct _foo;
+ at interface MyClass {
+ MyStruct _foo;
}
@property (assign, readwrite) const MyStruct& foo;
@@ -19,16 +17,38 @@
- (void) setFoo:(const MyStruct&)inFoo;
@end
-int main()
-{
- MyClass* myClass;
- MyStruct myStruct;
+void test0() {
+ MyClass* myClass;
+ MyStruct myStruct;
- myClass.foo = myStruct;
+ myClass.foo = myStruct;
- const MyStruct& currentMyStruct = myClass.foo;
- return 0;
+ const MyStruct& currentMyStruct = myClass.foo;
}
// CHECK: [[C:%.*]] = call %struct.MyStruct* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend
// CHECK: store %struct.MyStruct* [[C]], %struct.MyStruct** [[D:%.*]]
+
+namespace test1 {
+ struct A { A(); A(const A&); A&operator=(const A&); ~A(); };
+}
+ at interface Test1 {
+ test1::A ivar;
+}
+ at property const test1::A &prop1;
+ at end
+ at implementation Test1
+ at synthesize prop1 = ivar;
+ at end
+// CHECK: define internal [[A:%.*]]* @"\01-[Test1 prop1]"(
+// CHECK: [[SELF:%.*]] = alloca [[TEST1:%.*]]*, align 8
+// CHECK: [[T0:%.*]] = load [[TEST1]]** [[SELF]]
+// CHECK-NEXT: [[T1:%.*]] = bitcast [[TEST1]]* [[T0]] to i8*
+// CHECK-NEXT: [[T2:%.*]] = getelementptr inbounds i8* [[T1]], i64 0
+// CHECK-NEXT: [[T3:%.*]] = bitcast i8* [[T2]] to [[A]]*
+// CHECK-NEXT: ret [[A]]* [[T3]]
+
+// CHECK: define internal void @"\01-[Test1 setProp1:]"(
+// CHECK: call [[A]]* @_ZN5test11AaSERKS0_(
+// CHECK-NEXT: ret void
+
More information about the cfe-commits
mailing list