Index: cfe/trunk/lib/Sema/SemaPseudoObject.cpp =================================================================== --- cfe/trunk/lib/Sema/SemaPseudoObject.cpp +++ cfe/trunk/lib/Sema/SemaPseudoObject.cpp @@ -229,7 +229,7 @@ } /// Return true if assignments have a non-void result. - bool CanCaptureValue(Expr *exp) { + static bool CanCaptureValue(Expr *exp) { if (exp->isGLValue()) return true; QualType ty = exp->getType(); @@ -245,6 +245,20 @@ virtual ExprResult buildGet() = 0; virtual ExprResult buildSet(Expr *, SourceLocation, bool captureSetValueAsResult) = 0; + /// \brief Should the result of an assignment be the formal result of the + /// setter call or the value that was passed to the setter? + /// + /// Different pseudo-object language features use different language rules + /// for this. + /// The default is to use the set value. Currently, this affects the + /// behavior of simple assignments, compound assignments, and prefix + /// increment and decrement. + /// Postfix increment and decrement always use the getter result as the + /// expression result. + /// + /// If this method returns true, and the set value isn't capturable for + /// some reason, the result of the expression will be void. + virtual bool captureSetValueAsResult() const { return true; } }; /// A PseudoOpBuilder for Objective-C \@properties. @@ -339,6 +353,7 @@ Expr *rebuildAndCaptureObject(Expr *) override; ExprResult buildGet() override; ExprResult buildSet(Expr *op, SourceLocation, bool) override; + bool captureSetValueAsResult() const override { return false; } }; } @@ -455,9 +470,12 @@ // The result of the assignment, if not void, is the value set into // the l-value. - result = buildSet(result.get(), opcLoc, /*captureSetValueAsResult*/ true); + result = buildSet(result.get(), opcLoc, captureSetValueAsResult()); if (result.isInvalid()) return ExprError(); addSemanticExpr(result.get()); + if (!captureSetValueAsResult() && !result.get()->getType()->isVoidType() && + (result.get()->isTypeDependent() || CanCaptureValue(result.get()))) + setResultToLastSemantic(); return complete(syntactic); } @@ -499,9 +517,14 @@ // Store that back into the result. The value stored is the result // of a prefix operation. - result = buildSet(result.get(), opcLoc, UnaryOperator::isPrefix(opcode)); + result = buildSet(result.get(), opcLoc, UnaryOperator::isPrefix(opcode) && + captureSetValueAsResult()); if (result.isInvalid()) return ExprError(); addSemanticExpr(result.get()); + if (UnaryOperator::isPrefix(opcode) && !captureSetValueAsResult() && + !result.get()->getType()->isVoidType() && + (result.get()->isTypeDependent() || CanCaptureValue(result.get()))) + setResultToLastSemantic(); UnaryOperator *syntactic = new (S.Context) UnaryOperator(syntacticOp, opcode, resultType, Index: cfe/trunk/test/CodeGenCXX/ms-property.cpp =================================================================== --- cfe/trunk/test/CodeGenCXX/ms-property.cpp +++ cfe/trunk/test/CodeGenCXX/ms-property.cpp @@ -31,7 +31,7 @@ __declspec(property(get=GetX,put=PutX)) T x[]; T GetX(T i, T j) { return i+j; } T GetX() { return 0; } - void PutX(T i, T j, T k) { j = i = k; } + T PutX(T i, T j, T k) { return j = i = k; } __declspec(property(get=GetY,put=PutY)) T y[]; char GetY(char i, Test1 j) { return i+j.get_x(); } void PutY(char i, int j, double k) { j = i = k; } @@ -61,14 +61,16 @@ // CHECK: call float @"\01?GetX@?$St@M@@QEAAMMM@Z"(%class.St* %{{.+}}, float 2.230000e+02, float 1.100000e+01) float j1 = p2->x[223][11]; // CHECK: [[J1:%.+]] = load float, float* % - // CHECK-NEXT: call void @"\01?PutX@?$St@M@@QEAAXMMM@Z"(%class.St* %{{.+}}, float 2.300000e+01, float 1.000000e+00, float [[J1]]) - p2->x[23][1] = j1; + // CHECK-NEXT: [[CALL:%.+]] = call float @"\01?PutX@?$St@M@@QEAAMMMM@Z"(%class.St* %{{.+}}, float 2.300000e+01, float 1.000000e+00, float [[J1]]) + // CHECK-NEXT: [[CONV:%.+]] = fptosi float [[CALL]] to i32 + // CHECK-NEXT: store i32 [[CONV]], i32* + argc = p2->x[23][1] = j1; // CHECK: [[IDX:%.+]] = call i32 @"\01?idx@@YAHXZ"() // CHECK-NEXT: [[CONV:%.+]] = sitofp i32 [[IDX]] to float // CHECK-NEXT: [[GET:%.+]] = call float @"\01?GetX@?$St@M@@QEAAMMM@Z"(%class.St* %{{.+}}, float [[CONV]], float 1.000000e+00) // CHECK-NEXT: [[INC:%.+]] = fadd float [[GET]], 1.000000e+00 // CHECK-NEXT: [[CONV:%.+]] = sitofp i32 [[IDX]] to float - // CHECK-NEXT: call void @"\01?PutX@?$St@M@@QEAAXMMM@Z"(%class.St* %{{.+}}, float [[CONV]], float 1.000000e+00, float [[INC]]) + // CHECK-NEXT: call float @"\01?PutX@?$St@M@@QEAAMMMM@Z"(%class.St* %{{.+}}, float [[CONV]], float 1.000000e+00, float [[INC]]) ++p2->x[idx()][1]; // CHECK: call void @"\01??$foo@H@@YAXHH@Z"(i32 %{{.+}}, i32 %{{.+}}) foo(argc, (int)argv[0][0]); @@ -93,7 +95,7 @@ // CHECK: [[CAST1:%.+]] = sitofp i32 [[J]] to float // CHECK: [[J:%.+]] = load i32, i32* % // CHECK: [[CAST2:%.+]] = sitofp i32 [[J]] to float - // CHECK: call void @"\01?PutX@?$St@M@@QEAAXMMM@Z"(%class.St* [[P2_1]], float [[CAST2]], float [[CAST1]], float [[CAST]]) + // CHECK: call float @"\01?PutX@?$St@M@@QEAAMMMM@Z"(%class.St* [[P2_1]], float [[CAST2]], float [[CAST1]], float [[CAST]]) p2->x[j][j] = p2->y[p1->x[argc][0]][t]; // CHECK: [[CALL:%.+]] = call %class.Test1* @"\01?GetTest1@Test1@@SAPEAV1@XZ"() // CHECK-NEXT: call i32 @"\01?get_x@Test1@@QEBAHXZ"(%class.Test1* [[CALL]]) @@ -102,10 +104,10 @@ // CHECK: define linkonce_odr void @"\01??$foo@H@@YAXHH@Z"(i32 %{{.+}}, i32 %{{.+}}) // CHECK: call i32 @"\01?GetX@?$St@H@@QEAAHHH@Z"(%class.St{{.+}}* [[BAR:%.+]], i32 %{{.+}} i32 %{{.+}}) -// CHECK: call void @"\01?PutX@?$St@H@@QEAAXHHH@Z"(%class.St{{.+}}* [[BAR]], i32 %{{.+}}, i32 %{{.+}}, i32 %{{.+}}) +// CHECK: call i32 @"\01?PutX@?$St@H@@QEAAHHHH@Z"(%class.St{{.+}}* [[BAR]], i32 %{{.+}}, i32 %{{.+}}, i32 %{{.+}}) // CHECK: call i32 @"\01?GetX@?$St@H@@QEAAHHH@Z"(%class.St{{.+}}* [[BAR]], i32 %{{.+}} i32 %{{.+}}) // CHECK: call void @"\01?PutY@?$St@H@@QEAAXDHN@Z"(%class.St{{.+}}* [[BAR]], i8 %{{.+}}, i32 %{{.+}}, double %{{.+}} // CHECK: call i32 @"\01?GetX@?$St@H@@QEAAHHH@Z"(%class.St{{.+}}* [[BAR]], i32 %{{.+}} i32 %{{.+}}) // CHECK: call i8 @"\01?GetY@?$St@H@@QEAADDVTest1@@@Z"(%class.St{{.+}}* [[BAR]], i8 %{{.+}}, %class.Test1* %{{.+}}) -// CHECK: call void @"\01?PutX@?$St@H@@QEAAXHHH@Z"(%class.St{{.+}}* [[BAR]], i32 %{{.+}}, i32 %{{.+}}, i32 %{{.+}}) +// CHECK: call i32 @"\01?PutX@?$St@H@@QEAAHHHH@Z"(%class.St{{.+}}* [[BAR]], i32 %{{.+}}, i32 %{{.+}}, i32 %{{.+}}) #endif //HEADER Index: cfe/trunk/test/SemaCXX/ms-property-error.cpp =================================================================== --- cfe/trunk/test/SemaCXX/ms-property-error.cpp +++ cfe/trunk/test/SemaCXX/ms-property-error.cpp @@ -7,17 +7,19 @@ void PutX(int i, int j, int k) { j = i = k; } // expected-note {{'PutX' declared here}} }; +char *ptr; template class St { public: __declspec(property(get=GetX,put=PutX)) T x[]; T GetX(T i, T j) { return i+j; } // expected-note 3 {{'GetX' declared here}} - void PutX(T i, T j, T k) { j = i = k; } // expected-note 2 {{'PutX' declared here}} + T PutX(T i, T j, T k) { return j = i = k; } // expected-note 2 {{'PutX' declared here}} ~St() { x[1] = 0; // expected-error {{too few arguments to function call, expected 3, have 2}} x[2][3] = 4; ++x[2][3]; x[1][2] = x[3][4][5]; // expected-error {{too many arguments to function call, expected 2, have 3}} + ptr = x[1][2] = x[3][4]; // expected-error {{assigning to 'char *' from incompatible type 'int'}} } }; @@ -30,5 +32,6 @@ (p1->x[23]) = argc; // expected-error {{too few arguments to function call, expected 3, have 2}} float j1 = (p2->x); // expected-error {{too few arguments to function call, expected 2, have 0}} ((p2->x)[23])[1][2] = *argv; // expected-error {{too many arguments to function call, expected 3, have 4}} + argv = p2->x[11][22] = argc; // expected-error {{assigning to 'char **' from incompatible type 'float'}} return ++(((p2->x)[23])); // expected-error {{too few arguments to function call, expected 2, have 1}} } Index: cfe/trunk/test/SemaCXX/ms-property.cpp =================================================================== --- cfe/trunk/test/SemaCXX/ms-property.cpp +++ cfe/trunk/test/SemaCXX/ms-property.cpp @@ -29,7 +29,7 @@ public: __declspec(property(get=GetX,put=PutX)) T x[]; T GetX(T i, T j) { return i+j; } - void PutX(T i, T j, T k) { j = i = k; } + T PutX(T i, T j, T k) { return j = i = k; } ~St() { x[0][0] = x[1][1]; } }; @@ -52,6 +52,8 @@ ((p2->x)[23])[1] = j1; // CHECK-NEXT: ++(((p2->x)[23])[1]); ++(((p2->x)[23])[1]); + // CHECK-NEXT: j1 = ((p2->x)[23])[1] = j1; + j1 = ((p2->x)[23])[1] = j1; // CHECK-NEXT: return Test1::GetTest1()->X; return Test1::GetTest1()->X; }