r255218 - [MSVC] Fix for http://llvm.org/PR25636: indexed accessor property not supported correctly.

Alexey Bataev via cfe-commits cfe-commits at lists.llvm.org
Wed Dec 9 20:38:19 PST 2015


Author: abataev
Date: Wed Dec  9 22:38:18 2015
New Revision: 255218

URL: http://llvm.org/viewvc/llvm-project?rev=255218&view=rev
Log:
[MSVC] Fix for http://llvm.org/PR25636: indexed accessor property not supported correctly.
All problems described in http://llvm.org/PR25636 are implemented except for return value of the 'put' property. This patch fixes this problem with the indexed properties
Differential Revision: http://reviews.llvm.org/D15174

Modified:
    cfe/trunk/lib/Sema/SemaPseudoObject.cpp
    cfe/trunk/test/CodeGenCXX/ms-property.cpp
    cfe/trunk/test/SemaCXX/ms-property-error.cpp
    cfe/trunk/test/SemaCXX/ms-property.cpp

Modified: cfe/trunk/lib/Sema/SemaPseudoObject.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaPseudoObject.cpp?rev=255218&r1=255217&r2=255218&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaPseudoObject.cpp (original)
+++ cfe/trunk/lib/Sema/SemaPseudoObject.cpp Wed Dec  9 22:38:18 2015
@@ -229,7 +229,7 @@ namespace {
     }
 
     /// 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 @@ namespace {
     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 @@ namespace {
    Expr *rebuildAndCaptureObject(Expr *) override;
    ExprResult buildGet() override;
    ExprResult buildSet(Expr *op, SourceLocation, bool) override;
+   bool captureSetValueAsResult() const override { return false; }
  };
 }
 
@@ -455,9 +470,12 @@ PseudoOpBuilder::buildAssignmentOperatio
 
   // 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 @@ PseudoOpBuilder::buildIncDecOperation(Sc
 
   // 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,

Modified: cfe/trunk/test/CodeGenCXX/ms-property.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/ms-property.cpp?rev=255218&r1=255217&r2=255218&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/ms-property.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/ms-property.cpp Wed Dec  9 22:38:18 2015
@@ -31,7 +31,7 @@ public:
   __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 @@ int main(int argc, char **argv) {
   // CHECK: call float @"\01?GetX@?$St at M@@QEAAMMM at 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 at M@@QEAAXMMM at 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 at M@@QEAAMMMM at 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 at M@@QEAAMMM at 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 at M@@QEAAXMMM at Z"(%class.St* %{{.+}}, float [[CONV]], float 1.000000e+00, float [[INC]])
+  // CHECK-NEXT: call float @"\01?PutX@?$St at M@@QEAAMMMM at Z"(%class.St* %{{.+}}, float [[CONV]], float 1.000000e+00, float [[INC]])
   ++p2->x[idx()][1];
   // CHECK: call void @"\01??$foo at H@@YAXHH at Z"(i32 %{{.+}}, i32 %{{.+}})
   foo(argc, (int)argv[0][0]);
@@ -93,7 +95,7 @@ int main(int argc, char **argv) {
   // 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 at M@@QEAAXMMM at Z"(%class.St* [[P2_1]], float [[CAST2]], float [[CAST1]], float [[CAST]])
+  // CHECK: call float @"\01?PutX@?$St at M@@QEAAMMMM at 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 at Test1@@SAPEAV1 at XZ"()
   // CHECK-NEXT: call i32 @"\01?get_x at Test1@@QEBAHXZ"(%class.Test1* [[CALL]])
@@ -102,10 +104,10 @@ int main(int argc, char **argv) {
 
 // CHECK: define linkonce_odr void @"\01??$foo at H@@YAXHH at Z"(i32 %{{.+}}, i32 %{{.+}})
 // CHECK: call i32 @"\01?GetX@?$St at H@@QEAAHHH at Z"(%class.St{{.+}}* [[BAR:%.+]], i32 %{{.+}} i32 %{{.+}})
-// CHECK: call void @"\01?PutX@?$St at H@@QEAAXHHH at Z"(%class.St{{.+}}* [[BAR]], i32 %{{.+}}, i32 %{{.+}}, i32 %{{.+}})
+// CHECK: call i32 @"\01?PutX@?$St at H@@QEAAHHHH at Z"(%class.St{{.+}}* [[BAR]], i32 %{{.+}}, i32 %{{.+}}, i32 %{{.+}})
 // CHECK: call i32 @"\01?GetX@?$St at H@@QEAAHHH at Z"(%class.St{{.+}}* [[BAR]], i32 %{{.+}} i32 %{{.+}})
 // CHECK: call void @"\01?PutY@?$St at H@@QEAAXDHN at Z"(%class.St{{.+}}* [[BAR]], i8 %{{.+}}, i32 %{{.+}}, double %{{.+}}
 // CHECK: call i32 @"\01?GetX@?$St at H@@QEAAHHH at Z"(%class.St{{.+}}* [[BAR]], i32 %{{.+}} i32 %{{.+}})
 // CHECK: call i8 @"\01?GetY@?$St at H@@QEAADDVTest1@@@Z"(%class.St{{.+}}* [[BAR]], i8 %{{.+}}, %class.Test1* %{{.+}})
-// CHECK: call void @"\01?PutX@?$St at H@@QEAAXHHH at Z"(%class.St{{.+}}* [[BAR]], i32 %{{.+}}, i32 %{{.+}}, i32 %{{.+}})
+// CHECK: call i32 @"\01?PutX@?$St at H@@QEAAHHHH at Z"(%class.St{{.+}}* [[BAR]], i32 %{{.+}}, i32 %{{.+}}, i32 %{{.+}})
 #endif //HEADER

Modified: cfe/trunk/test/SemaCXX/ms-property-error.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/ms-property-error.cpp?rev=255218&r1=255217&r2=255218&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/ms-property-error.cpp (original)
+++ cfe/trunk/test/SemaCXX/ms-property-error.cpp Wed Dec  9 22:38:18 2015
@@ -7,17 +7,19 @@ public:
   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 @@ int main(int argc, char **argv) {
   (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}}
 }

Modified: cfe/trunk/test/SemaCXX/ms-property.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/ms-property.cpp?rev=255218&r1=255217&r2=255218&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/ms-property.cpp (original)
+++ cfe/trunk/test/SemaCXX/ms-property.cpp Wed Dec  9 22:38:18 2015
@@ -29,7 +29,7 @@ class St {
 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 @@ int main(int argc, char **argv) {
   ((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;
 }




More information about the cfe-commits mailing list