1 // RUN: %clang_cc1 -no-opaque-pointers -emit-llvm -triple=x86_64-pc-win32 -fms-compatibility %s -o - | FileCheck %s
2 // RUN: %clang_cc1 -no-opaque-pointers -triple=x86_64-pc-win32 -fms-compatibility -emit-pch -o %t %s
3 // RUN: %clang_cc1 -no-opaque-pointers -emit-llvm -triple=x86_64-pc-win32 -fms-compatibility -include-pch %t -verify %s -o - | FileCheck %s
4 // expected-no-diagnostics
5
6 #ifndef HEADER
7 #define HEADER
8
9 class Test1 {
10 private:
11 int x_;
12 double y_;
13
14 public:
Test1(int x)15 Test1(int x) : x_(x) {}
16 __declspec(property(get = get_x)) int X;
get_x() const17 int get_x() const { return x_; }
GetTest1()18 static Test1 *GetTest1() { return new Test1(10); }
19 };
20
21 class S {
22 public:
23 __declspec(property(get=GetX,put=PutX)) int x[];
GetX(int i,int j)24 int GetX(int i, int j) { return i+j; }
PutX(int i,int j,int k)25 void PutX(int i, int j, int k) { j = i = k; }
26 };
27
28 template <typename T>
29 class St {
30 public:
31 __declspec(property(get=GetX,put=PutX)) T x[];
GetX(T i,T j)32 T GetX(T i, T j) { return i+j; }
GetX()33 T GetX() { return 0; }
PutX(T i,T j,T k)34 T PutX(T i, T j, T k) { return j = i = k; }
35 __declspec(property(get=GetY,put=PutY)) T y[];
GetY(char i,Test1 j)36 char GetY(char i, Test1 j) { return i+j.get_x(); }
PutY(char i,int j,double k)37 void PutY(char i, int j, double k) { j = i = k; }
38 };
39
40 template <typename T>
foo(T i,T j)41 void foo(T i, T j) {
42 St<T> bar;
43 Test1 t(i);
44 bar.x[i][j] = bar.x[i][j];
45 bar.y[t.X][j] = bar.x[i][j];
46 bar.x[i][j] = bar.y[bar.x[i][j]][t];
47 }
48
idx()49 int idx() { return 7; }
50
51 // CHECK-LABEL: main
main(int argc,char ** argv)52 int main(int argc, char **argv) {
53 Test1 t(argc);
54 S *p1 = 0;
55 St<float> *p2 = 0;
56 // CHECK: call noundef i32 @"?GetX@S@@QEAAHHH@Z"(%class.S* {{[^,]*}} %{{.+}}, i32 noundef 223, i32 noundef 11)
57 int j = p1->x[223][11];
58 // CHECK: [[J:%.+]] = load i32, i32* %
59 // CHECK-NEXT: call void @"?PutX@S@@QEAAXHHH@Z"(%class.S* {{[^,]*}} %{{.+}}, i32 noundef 23, i32 noundef 1, i32 noundef [[J]])
60 p1->x[23][1] = j;
61 // CHECK: call noundef float @"?GetX@?$St@M@@QEAAMMM@Z"(%class.St* {{[^,]*}} %{{.+}}, float noundef 2.230000e+02, float noundef 1.100000e+01)
62 float j1 = p2->x[223][11];
63 // CHECK: [[J1:%.+]] = load float, float* %
64 // CHECK-NEXT: [[CALL:%.+]] = call noundef float @"?PutX@?$St@M@@QEAAMMMM@Z"(%class.St* {{[^,]*}} %{{.+}}, float noundef 2.300000e+01, float noundef 1.000000e+00, float noundef [[J1]])
65 // CHECK-NEXT: [[CONV:%.+]] = fptosi float [[CALL]] to i32
66 // CHECK-NEXT: store i32 [[CONV]], i32*
67 argc = p2->x[23][1] = j1;
68 // CHECK: [[IDX:%.+]] = call noundef i32 @"?idx@@YAHXZ"()
69 // CHECK-NEXT: [[CONV:%.+]] = sitofp i32 [[IDX]] to float
70 // CHECK-NEXT: [[GET:%.+]] = call noundef float @"?GetX@?$St@M@@QEAAMMM@Z"(%class.St* {{[^,]*}} %{{.+}}, float noundef [[CONV]], float noundef 1.000000e+00)
71 // CHECK-NEXT: [[INC:%.+]] = fadd float [[GET]], 1.000000e+00
72 // CHECK-NEXT: [[CONV:%.+]] = sitofp i32 [[IDX]] to float
73 // CHECK-NEXT: call noundef float @"?PutX@?$St@M@@QEAAMMMM@Z"(%class.St* {{[^,]*}} %{{.+}}, float noundef [[CONV]], float noundef 1.000000e+00, float noundef [[INC]])
74 ++p2->x[idx()][1];
75 // CHECK: call void @"??$foo@H@@YAXHH@Z"(i32 noundef %{{.+}}, i32 noundef %{{.+}})
76 foo(argc, (int)argv[0][0]);
77 // CHECK: [[P2:%.+]] = load %class.St*, %class.St** %
78 // CHECK: [[P1:%.+]] = load %class.S*, %class.S** %
79 // CHECK: [[P1_X_22_33:%.+]] = call noundef i32 @"?GetX@S@@QEAAHHH@Z"(%class.S* {{[^,]*}} [[P1]], i32 noundef 22, i32 noundef 33)
80 // CHECK: [[CAST:%.+]] = sitofp i32 [[P1_X_22_33]] to double
81 // CHECK: [[ARGC:%.+]] = load i32, i32* %
82 // CHECK: [[T_X:%.+]] = call noundef i32 @"?get_x@Test1@@QEBAHXZ"(%class.Test1* {{[^,]*}} %{{.+}})
83 // CHECK: [[CAST2:%.+]] = trunc i32 [[T_X]] to i8
84 // CHECK: call void @"?PutY@?$St@M@@QEAAXDHN@Z"(%class.St* {{[^,]*}} [[P2]], i8 noundef [[CAST2]], i32 noundef [[ARGC]], double noundef [[CAST]])
85 p2->y[t.X][argc] = p1->x[22][33];
86 // CHECK: [[P2_1:%.+]] = load %class.St*, %class.St**
87 // CHECK: [[P2_2:%.+]] = load %class.St*, %class.St**
88 // CHECK: [[P1:%.+]] = load %class.S*, %class.S**
89 // CHECK: [[ARGC:%.+]] = load i32, i32* %
90 // CHECK: [[P1_X_ARGC_0:%.+]] = call noundef i32 @"?GetX@S@@QEAAHHH@Z"(%class.S* {{[^,]*}} [[P1]], i32 noundef [[ARGC]], i32 noundef 0)
91 // CHECK: [[CAST:%.+]] = trunc i32 [[P1_X_ARGC_0]] to i8
92 // CHECK: [[P2_Y_p1_X_ARGC_0_T:%.+]] = call noundef i8 @"?GetY@?$St@M@@QEAADDVTest1@@@Z"(%class.St* {{[^,]*}} [[P2_2]], i8 noundef [[CAST]], %class.Test1* noundef %{{.+}})
93 // CHECK: [[CAST:%.+]] = sitofp i8 [[P2_Y_p1_X_ARGC_0_T]] to float
94 // CHECK: [[J:%.+]] = load i32, i32* %
95 // CHECK: [[CAST1:%.+]] = sitofp i32 [[J]] to float
96 // CHECK: [[J:%.+]] = load i32, i32* %
97 // CHECK: [[CAST2:%.+]] = sitofp i32 [[J]] to float
98 // CHECK: call noundef float @"?PutX@?$St@M@@QEAAMMMM@Z"(%class.St* {{[^,]*}} [[P2_1]], float noundef [[CAST2]], float noundef [[CAST1]], float noundef [[CAST]])
99 p2->x[j][j] = p2->y[p1->x[argc][0]][t];
100 // CHECK: [[CALL:%.+]] = call noundef %class.Test1* @"?GetTest1@Test1@@SAPEAV1@XZ"()
101 // CHECK-NEXT: call noundef i32 @"?get_x@Test1@@QEBAHXZ"(%class.Test1* {{[^,]*}} [[CALL]])
102 return Test1::GetTest1()->X;
103 }
104
105 // CHECK: define linkonce_odr dso_local void @"??$foo@H@@YAXHH@Z"(i32 noundef %{{.+}}, i32 noundef %{{.+}})
106 // CHECK: call noundef i32 @"?GetX@?$St@H@@QEAAHHH@Z"(%class.St{{.+}}* {{[^,]*}} [[BAR:%.+]], i32 noundef %{{.+}} i32 noundef %{{.+}})
107 // CHECK: call noundef i32 @"?PutX@?$St@H@@QEAAHHHH@Z"(%class.St{{.+}}* {{[^,]*}} [[BAR]], i32 noundef %{{.+}}, i32 noundef %{{.+}}, i32 noundef %{{.+}})
108 // CHECK: call noundef i32 @"?GetX@?$St@H@@QEAAHHH@Z"(%class.St{{.+}}* {{[^,]*}} [[BAR]], i32 noundef %{{.+}} i32 noundef %{{.+}})
109 // CHECK: call void @"?PutY@?$St@H@@QEAAXDHN@Z"(%class.St{{.+}}* {{[^,]*}} [[BAR]], i8 noundef %{{.+}}, i32 noundef %{{.+}}, double noundef %{{.+}}
110 // CHECK: call noundef i32 @"?GetX@?$St@H@@QEAAHHH@Z"(%class.St{{.+}}* {{[^,]*}} [[BAR]], i32 noundef %{{.+}} i32 noundef %{{.+}})
111 // CHECK: call noundef i8 @"?GetY@?$St@H@@QEAADDVTest1@@@Z"(%class.St{{.+}}* {{[^,]*}} [[BAR]], i8 noundef %{{.+}}, %class.Test1* noundef %{{.+}})
112 // CHECK: call noundef i32 @"?PutX@?$St@H@@QEAAHHHH@Z"(%class.St{{.+}}* {{[^,]*}} [[BAR]], i32 noundef %{{.+}}, i32 noundef %{{.+}}, i32 noundef %{{.+}})
113 #endif //HEADER
114