summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPawel Wodnicki <pawel@32bitmicro.com>2012-11-19 21:01:40 +0000
committerPawel Wodnicki <pawel@32bitmicro.com>2012-11-19 21:01:40 +0000
commit0d7bc297f7165a7dbefdcad3b4043c275d35c13e (patch)
tree47d772ce304cc4152a5a1cc3847aa963cb3a954c
parente8552efa949bad0fdf2f3221d37083c5056a0abf (diff)
downloadclang-0d7bc297f7165a7dbefdcad3b4043c275d35c13e.tar.gz
clang-0d7bc297f7165a7dbefdcad3b4043c275d35c13e.tar.bz2
clang-0d7bc297f7165a7dbefdcad3b4043c275d35c13e.tar.xz
Merging r167884,r167920 from trunk into 3.2 release branch
r167884 Don't try to save the assigned value in a Objective-C property assignment if the type of the value is a non-trivial class type. Fixes PR14318. (There's a minor ObjC++ language change here: given that we can't save the value, the type of the assignment expression is void in such cases.) r167920 PR14279: Work around this major miscompilation by treating move operations as non-trivial if they would not call a move operation, even if they would in fact call a trivial copy operation. A proper fix is to follow, but this small directed fix is intended for porting to the 3.2 release branch. git-svn-id: https://llvm.org/svn/llvm-project/cfe/branches/release_32@168324 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/AST/DeclCXX.cpp19
-rw-r--r--lib/Sema/SemaPseudoObject.cpp22
-rw-r--r--test/CodeGenCXX/cxx11-special-members.cpp32
-rw-r--r--test/CodeGenObjCXX/property-objects.mm22
-rw-r--r--test/SemaObjCXX/properties.mm23
5 files changed, 100 insertions, 18 deletions
diff --git a/lib/AST/DeclCXX.cpp b/lib/AST/DeclCXX.cpp
index 9db33357a6..82e630acef 100644
--- a/lib/AST/DeclCXX.cpp
+++ b/lib/AST/DeclCXX.cpp
@@ -240,10 +240,13 @@ CXXRecordDecl::setBases(CXXBaseSpecifier const * const *Bases,
// -- the constructor selected to copy/move each direct base class
// subobject is trivial, and
// FIXME: C++0x: We need to only consider the selected constructor
- // instead of all of them.
+ // instead of all of them. For now, we treat a move constructor as being
+ // non-trivial if it calls anything other than a trivial move constructor.
if (!BaseClassDecl->hasTrivialCopyConstructor())
data().HasTrivialCopyConstructor = false;
- if (!BaseClassDecl->hasTrivialMoveConstructor())
+ if (!BaseClassDecl->hasTrivialMoveConstructor() ||
+ !(BaseClassDecl->hasDeclaredMoveConstructor() ||
+ BaseClassDecl->needsImplicitMoveConstructor()))
data().HasTrivialMoveConstructor = false;
// C++0x [class.copy]p27:
@@ -255,7 +258,9 @@ CXXRecordDecl::setBases(CXXBaseSpecifier const * const *Bases,
// of all of them.
if (!BaseClassDecl->hasTrivialCopyAssignment())
data().HasTrivialCopyAssignment = false;
- if (!BaseClassDecl->hasTrivialMoveAssignment())
+ if (!BaseClassDecl->hasTrivialMoveAssignment() ||
+ !(BaseClassDecl->hasDeclaredMoveAssignment() ||
+ BaseClassDecl->needsImplicitMoveAssignment()))
data().HasTrivialMoveAssignment = false;
// C++11 [class.ctor]p6:
@@ -830,7 +835,9 @@ NotASpecialMember:;
// FIXME: C++0x: We don't correctly model 'selected' constructors.
if (!FieldRec->hasTrivialCopyConstructor())
data().HasTrivialCopyConstructor = false;
- if (!FieldRec->hasTrivialMoveConstructor())
+ if (!FieldRec->hasTrivialMoveConstructor() ||
+ !(FieldRec->hasDeclaredMoveConstructor() ||
+ FieldRec->needsImplicitMoveConstructor()))
data().HasTrivialMoveConstructor = false;
// C++0x [class.copy]p27:
@@ -842,7 +849,9 @@ NotASpecialMember:;
// FIXME: C++0x: We don't correctly model 'selected' operators.
if (!FieldRec->hasTrivialCopyAssignment())
data().HasTrivialCopyAssignment = false;
- if (!FieldRec->hasTrivialMoveAssignment())
+ if (!FieldRec->hasTrivialMoveAssignment() ||
+ !(FieldRec->hasDeclaredMoveAssignment() ||
+ FieldRec->needsImplicitMoveAssignment()))
data().HasTrivialMoveAssignment = false;
if (!FieldRec->hasTrivialDestructor())
diff --git a/lib/Sema/SemaPseudoObject.cpp b/lib/Sema/SemaPseudoObject.cpp
index 37d9e77548..a8d75b290f 100644
--- a/lib/Sema/SemaPseudoObject.cpp
+++ b/lib/Sema/SemaPseudoObject.cpp
@@ -198,7 +198,14 @@ namespace {
}
/// Return true if assignments have a non-void result.
- virtual bool assignmentsHaveResult() { return true; }
+ bool CanCaptureValueOfType(QualType ty) {
+ assert(!ty->isIncompleteType());
+ assert(!ty->isDependentType());
+
+ if (const CXXRecordDecl *ClassDecl = ty->getAsCXXRecordDecl())
+ return ClassDecl->isTriviallyCopyable();
+ return true;
+ }
virtual Expr *rebuildAndCaptureObject(Expr *) = 0;
virtual ExprResult buildGet() = 0;
@@ -380,7 +387,7 @@ PseudoOpBuilder::buildAssignmentOperation(Scope *Sc, SourceLocation opcLoc,
// The result of the assignment, if not void, is the value set into
// the l-value.
- result = buildSet(result.take(), opcLoc, assignmentsHaveResult());
+ result = buildSet(result.take(), opcLoc, /*captureSetValueAsResult*/ true);
if (result.isInvalid()) return ExprError();
addSemanticExpr(result.take());
@@ -404,7 +411,7 @@ PseudoOpBuilder::buildIncDecOperation(Scope *Sc, SourceLocation opcLoc,
QualType resultType = result.get()->getType();
// That's the postfix result.
- if (UnaryOperator::isPostfix(opcode) && assignmentsHaveResult()) {
+ if (UnaryOperator::isPostfix(opcode) && CanCaptureValueOfType(resultType)) {
result = capture(result.take());
setResultToLastSemantic();
}
@@ -423,8 +430,7 @@ PseudoOpBuilder::buildIncDecOperation(Scope *Sc, SourceLocation opcLoc,
// Store that back into the result. The value stored is the result
// of a prefix operation.
- result = buildSet(result.take(), opcLoc,
- UnaryOperator::isPrefix(opcode) && assignmentsHaveResult());
+ result = buildSet(result.take(), opcLoc, UnaryOperator::isPrefix(opcode));
if (result.isInvalid()) return ExprError();
addSemanticExpr(result.take());
@@ -696,7 +702,8 @@ ExprResult ObjCPropertyOpBuilder::buildSet(Expr *op, SourceLocation opcLoc,
ObjCMessageExpr *msgExpr =
cast<ObjCMessageExpr>(msg.get()->IgnoreImplicit());
Expr *arg = msgExpr->getArg(0);
- msgExpr->setArg(0, captureValueAsResult(arg));
+ if (CanCaptureValueOfType(arg->getType()))
+ msgExpr->setArg(0, captureValueAsResult(arg));
}
return msg;
@@ -1312,7 +1319,8 @@ ExprResult ObjCSubscriptOpBuilder::buildSet(Expr *op, SourceLocation opcLoc,
ObjCMessageExpr *msgExpr =
cast<ObjCMessageExpr>(msg.get()->IgnoreImplicit());
Expr *arg = msgExpr->getArg(0);
- msgExpr->setArg(0, captureValueAsResult(arg));
+ if (CanCaptureValueOfType(arg->getType()))
+ msgExpr->setArg(0, captureValueAsResult(arg));
}
return msg;
diff --git a/test/CodeGenCXX/cxx11-special-members.cpp b/test/CodeGenCXX/cxx11-special-members.cpp
new file mode 100644
index 0000000000..59461f9e2f
--- /dev/null
+++ b/test/CodeGenCXX/cxx11-special-members.cpp
@@ -0,0 +1,32 @@
+// RUN: %clang_cc1 %s -std=c++11 -emit-llvm -o - -triple=i686-linux-gnu | FileCheck %s
+
+struct A {
+ A(const A&);
+ A &operator=(const A&);
+};
+
+struct B {
+ A a;
+ B(B&&) = default;
+ B &operator=(B&&) = default;
+};
+
+// CHECK: define {{.*}} @_Z2f1
+void f1(B &x) {
+ // CHECK-NOT: memcpy
+ // CHECK: call {{.*}} @_ZN1BC1EOS_(
+ B b(static_cast<B&&>(x));
+}
+
+// CHECK: define {{.*}} @_Z2f2
+void f2(B &x, B &y) {
+ // CHECK-NOT: memcpy
+ // CHECK: call {{.*}} @_ZN1BaSEOS_(
+ x = static_cast<B&&>(y);
+}
+
+// CHECK: define {{.*}} @_ZN1BaSEOS_(
+// CHECK: call {{.*}} @_ZN1AaSERKS_(
+
+// CHECK: define {{.*}} @_ZN1BC2EOS_(
+// CHECK: call {{.*}} @_ZN1AC1ERKS_(
diff --git a/test/CodeGenObjCXX/property-objects.mm b/test/CodeGenObjCXX/property-objects.mm
index 6dfcc27f19..a3c2ed3746 100644
--- a/test/CodeGenObjCXX/property-objects.mm
+++ b/test/CodeGenObjCXX/property-objects.mm
@@ -1,8 +1,4 @@
// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -emit-llvm -o - | FileCheck %s
-// CHECK-NOT: callq _objc_msgSend_stret
-// CHECK: call void @_ZN1SC1ERKS_
-// CHECK: call %class.S* @_ZN1SaSERKS_
-// CHECK: call %struct.CGRect* @_ZN6CGRectaSERKS_
class S {
public:
@@ -19,13 +15,14 @@ struct CGRect {
S position;
CGRect bounds;
}
+
@property(assign, nonatomic) S position;
@property CGRect bounds;
@property CGRect frame;
- (void)setFrame:(CGRect)frameRect;
- (CGRect)frame;
- (void) initWithOwner;
-- (struct CGRect)extent;
+- (CGRect)extent;
- (void)dealloc;
@end
@@ -33,6 +30,11 @@ struct CGRect {
@synthesize position;
@synthesize bounds;
@synthesize frame;
+
+// CHECK: define internal void @"\01-[I setPosition:]"
+// CHECK: call %class.S* @_ZN1SaSERKS_
+// CHECK-NEXT: ret void
+
- (void)setFrame:(CGRect)frameRect {}
- (CGRect)frame {return bounds;}
@@ -42,14 +44,20 @@ struct CGRect {
labelLayerFrame = self.bounds;
_labelLayer.frame = labelLayerFrame;
}
+
// rdar://8366604
- (void)dealloc
{
CGRect cgrect = self.extent;
}
- (struct CGRect)extent {return bounds;}
+
@end
+// CHECK: define i32 @main
+// CHECK: call void @_ZN1SC1ERKS_(%class.S* [[AGGTMP:%[a-zA-Z0-9\.]+]], %class.S* {{%[a-zA-Z0-9\.]+}})
+// CHECK: call void bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to void (i8*, i8*, %class.S*)*)(i8* {{%[a-zA-Z0-9\.]+}}, i8* {{%[a-zA-Z0-9\.]+}}, %class.S* [[AGGTMP]])
+// CHECK-NEXT: ret i32 0
int main() {
I *i;
S s1;
@@ -59,7 +67,9 @@ int main() {
// rdar://8379892
// CHECK: define void @_Z1fP1A
-// CHECK: @objc_msgSend to void
+// CHECK: call void @_ZN1XC1Ev(%struct.X* [[LVTEMP:%[a-zA-Z0-9\.]+]])
+// CHECK: call void @_ZN1XC1ERKS_(%struct.X* [[AGGTMP:%[a-zA-Z0-9\.]+]], %struct.X* [[LVTEMP]])
+// CHECK: call void bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to void (i8*, i8*, %struct.X*)*)({{.*}} %struct.X* [[AGGTMP]])
struct X {
X();
X(const X&);
diff --git a/test/SemaObjCXX/properties.mm b/test/SemaObjCXX/properties.mm
index 3c6b138586..0783eebc11 100644
--- a/test/SemaObjCXX/properties.mm
+++ b/test/SemaObjCXX/properties.mm
@@ -106,3 +106,26 @@ void test7(Test7 *ptr) {
delete ptr.implicit_struct_property;
delete ptr.explicit_struct_property;
}
+
+// Make sure the returned value from property assignment is void,
+// because there isn't any other viable way to handle it for
+// non-trivial classes.
+class NonTrivial1 {
+public:
+ ~NonTrivial1();
+};
+class NonTrivial2 {
+public:
+ NonTrivial2();
+ NonTrivial2(const NonTrivial2&);
+};
+@interface TestNonTrivial
+@property(assign, nonatomic) NonTrivial1 p1;
+@property(assign, nonatomic) NonTrivial2 p2;
+@end
+TestNonTrivial *TestNonTrivialObj;
+
+extern void* VoidType;
+extern decltype(TestNonTrivialObj.p1 = NonTrivial1())* VoidType;
+extern decltype(TestNonTrivialObj.p2 = NonTrivial2())* VoidType;
+