[cfe-commits] r113885 - in /cfe/trunk: include/clang/Sema/Sema.h lib/AST/ExprClassification.cpp lib/Sema/SemaExpr.cpp test/CodeGenObjCXX/property-dot-copy.mm
Fariborz Jahanian
fjahanian at apple.com
Tue Sep 14 16:02:38 PDT 2010
Author: fjahanian
Date: Tue Sep 14 18:02:38 2010
New Revision: 113885
URL: http://llvm.org/viewvc/llvm-project?rev=113885&view=rev
Log:
RHS of property expression assignment requires
copy initialization before passing it to
a setter. Fixes radar 8427922.
Added:
cfe/trunk/test/CodeGenObjCXX/property-dot-copy.mm
Modified:
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/AST/ExprClassification.cpp
cfe/trunk/lib/Sema/SemaExpr.cpp
Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=113885&r1=113884&r2=113885&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Tue Sep 14 18:02:38 2010
@@ -4107,6 +4107,9 @@
// For compound assignment, pass both expressions and the converted type.
QualType CheckAssignmentOperands( // C99 6.5.16.[1,2]
Expr *lex, Expr *&rex, SourceLocation OpLoc, QualType convertedType);
+
+ void ConvertPropertyAssignment(Expr *LHS, Expr *&RHS, QualType& LHSTy);
+
QualType CheckCommaOperands( // C99 6.5.17
Expr *lex, Expr *&rex, SourceLocation OpLoc);
QualType CheckConditionalOperands( // C99 6.5.15
Modified: cfe/trunk/lib/AST/ExprClassification.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprClassification.cpp?rev=113885&r1=113884&r2=113885&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ExprClassification.cpp (original)
+++ cfe/trunk/lib/AST/ExprClassification.cpp Tue Sep 14 18:02:38 2010
@@ -478,7 +478,8 @@
// Records with any const fields (recursively) are not modifiable.
if (const RecordType *R = CT->getAs<RecordType>()) {
- assert((isa<ObjCImplicitSetterGetterRefExpr>(E) ||
+ assert((isa<ObjCImplicitSetterGetterRefExpr>(E) ||
+ isa<ObjCPropertyRefExpr>(E) ||
!Ctx.getLangOptions().CPlusPlus) &&
"C++ struct assignment should be resolved by the "
"copy assignment operator.");
Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=113885&r1=113884&r2=113885&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Tue Sep 14 18:02:38 2010
@@ -6016,17 +6016,7 @@
if (CompoundType.isNull()) {
QualType LHSTy(LHSType);
// Simple assignment "x = y".
- if (const ObjCImplicitSetterGetterRefExpr *OISGE =
- dyn_cast<ObjCImplicitSetterGetterRefExpr>(LHS)) {
- // If using property-dot syntax notation for assignment, and there is a
- // setter, RHS expression is being passed to the setter argument. So,
- // type conversion (and comparison) is RHS to setter's argument type.
- if (const ObjCMethodDecl *SetterMD = OISGE->getSetterMethod()) {
- ObjCMethodDecl::param_iterator P = SetterMD->param_begin();
- LHSTy = (*P)->getType();
- }
- }
-
+ ConvertPropertyAssignment(LHS, RHS, LHSTy);
ConvTy = CheckSingleAssignmentConstraints(LHSTy, RHS);
// Special case of NSObject attributes on c-style pointer types.
if (ConvTy == IncompatiblePointer &&
@@ -6181,6 +6171,34 @@
? ResType : ResType.getUnqualifiedType();
}
+void Sema::ConvertPropertyAssignment(Expr *LHS, Expr *&RHS, QualType& LHSTy) {
+ bool copyInit = false;
+ if (const ObjCImplicitSetterGetterRefExpr *OISGE =
+ dyn_cast<ObjCImplicitSetterGetterRefExpr>(LHS)) {
+ // If using property-dot syntax notation for assignment, and there is a
+ // setter, RHS expression is being passed to the setter argument. So,
+ // type conversion (and comparison) is RHS to setter's argument type.
+ if (const ObjCMethodDecl *SetterMD = OISGE->getSetterMethod()) {
+ ObjCMethodDecl::param_iterator P = SetterMD->param_begin();
+ LHSTy = (*P)->getType();
+ }
+ copyInit = (getLangOptions().CPlusPlus && LHSTy->isRecordType());
+ }
+ else
+ copyInit = (getLangOptions().CPlusPlus && isa<ObjCPropertyRefExpr>(LHS) &&
+ LHSTy->isRecordType());
+ if (copyInit) {
+ InitializedEntity Entity =
+ InitializedEntity::InitializeParameter(LHSTy);
+ Expr *Arg = RHS;
+ ExprResult ArgE = PerformCopyInitialization(Entity, SourceLocation(),
+ Owned(Arg));
+ if (!ArgE.isInvalid())
+ RHS = ArgE.takeAs<Expr>();
+ }
+}
+
+
/// getPrimaryDecl - Helper function for CheckAddressOfOperand().
/// This routine allows us to typecheck complex/recursive expressions
/// where the declaration is needed for type checking. We only need to
@@ -6698,8 +6716,9 @@
BinaryOperatorKind Opc,
Expr *lhs, Expr *rhs) {
if (getLangOptions().CPlusPlus &&
- (!isa<ObjCImplicitSetterGetterRefExpr>(lhs) ||
- rhs->isTypeDependent()) &&
+ ((!isa<ObjCImplicitSetterGetterRefExpr>(lhs) &&
+ !isa<ObjCPropertyRefExpr>(lhs))
+ || rhs->isTypeDependent()) &&
(lhs->getType()->isOverloadableType() ||
rhs->getType()->isOverloadableType())) {
// Find all of the overloaded operators visible from this
Added: cfe/trunk/test/CodeGenObjCXX/property-dot-copy.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjCXX/property-dot-copy.mm?rev=113885&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenObjCXX/property-dot-copy.mm (added)
+++ cfe/trunk/test/CodeGenObjCXX/property-dot-copy.mm Tue Sep 14 18:02:38 2010
@@ -0,0 +1,34 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -fobjc-nonfragile-abi -o - %s | FileCheck %s
+// rdar://8427922
+
+struct Vector3D
+{
+ float x, y, z;
+ Vector3D();
+ Vector3D(const Vector3D &inVector);
+ Vector3D(float initX, float initY, float initZ);
+ Vector3D &operator=(const Vector3D & rhs);
+};
+
+ at interface Object3D
+{
+ Vector3D position;
+ Vector3D length;
+}
+ at property (assign) Vector3D position;
+- (Vector3D) length;
+- (void) setLength: (Vector3D)arg;
+ at end
+
+int main ()
+{
+ Object3D *myObject;
+ Vector3D V3D(1.0f, 1.0f, 1.0f);
+// CHECK: call void @_ZN8Vector3DC1ERKS_
+ myObject.position = V3D;
+
+// CHECK: call void @_ZN8Vector3DC1ERKS_
+ myObject.length = V3D;
+
+ return 0;
+}
More information about the cfe-commits
mailing list