ABataev updated this revision to Diff 41848. ABataev added a comment. Update after review
http://reviews.llvm.org/D15174 Files: lib/Sema/SemaPseudoObject.cpp test/CodeGenCXX/ms-property.cpp test/SemaCXX/ms-property-error.cpp test/SemaCXX/ms-property.cpp
Index: lib/Sema/SemaPseudoObject.cpp =================================================================== --- lib/Sema/SemaPseudoObject.cpp +++ lib/Sema/SemaPseudoObject.cpp @@ -229,7 +229,7 @@ } /// Return true if assignments have a non-void result. - bool CanCaptureValue(Expr *exp) { + bool CanCaptureValue(Expr *exp) const { if (exp->isGLValue()) return true; QualType ty = exp->getType(); @@ -245,6 +245,7 @@ virtual ExprResult buildGet() = 0; virtual ExprResult buildSet(Expr *, SourceLocation, bool captureSetValueAsResult) = 0; + virtual bool useSetterResultAsExprResult(Expr *) const { return false; } }; /// A PseudoOpBuilder for Objective-C \@properties. @@ -339,6 +340,7 @@ Expr *rebuildAndCaptureObject(Expr *) override; ExprResult buildGet() override; ExprResult buildSet(Expr *op, SourceLocation, bool) override; + bool useSetterResultAsExprResult(Expr *) const override; }; } @@ -458,6 +460,8 @@ result = buildSet(result.get(), opcLoc, /*captureSetValueAsResult*/ true); if (result.isInvalid()) return ExprError(); addSemanticExpr(result.get()); + if (useSetterResultAsExprResult(result.get())) + setResultToLastSemantic(); return complete(syntactic); } @@ -502,6 +506,9 @@ result = buildSet(result.get(), opcLoc, UnaryOperator::isPrefix(opcode)); if (result.isInvalid()) return ExprError(); addSemanticExpr(result.get()); + if (UnaryOperator::isPrefix(opcode) && + useSetterResultAsExprResult(result.get())) + setResultToLastSemantic(); UnaryOperator *syntactic = new (S.Context) UnaryOperator(syntacticOp, opcode, resultType, @@ -1497,6 +1504,12 @@ op->getSourceRange().getEnd()); } +bool MSPropertyOpBuilder::useSetterResultAsExprResult(Expr *ResExpr) const { + assert(ResExpr); + return !ResExpr->getType()->isVoidType() && + (ResExpr->getType()->isDependentType() || CanCaptureValue(ResExpr)); +} + //===----------------------------------------------------------------------===// // General Sema routines. //===----------------------------------------------------------------------===// Index: test/SemaCXX/ms-property.cpp =================================================================== --- test/SemaCXX/ms-property.cpp +++ 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; } Index: test/SemaCXX/ms-property-error.cpp =================================================================== --- test/SemaCXX/ms-property-error.cpp +++ 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 <typename T> 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: test/CodeGenCXX/ms-property.cpp =================================================================== --- test/CodeGenCXX/ms-property.cpp +++ 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,19 +95,19 @@ // 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]]) return Test1::GetTest1()->X; } // 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
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits