blob: 49e957b58e339c2b42990de7f64aec5c10148680 [file] [log] [blame]
Alexey Bataev69103472015-10-14 04:05:42 +00001// RUN: %clang_cc1 -emit-llvm -triple=x86_64-pc-win32 -fms-compatibility %s -o - | FileCheck %s
Alexey Bataevf7630272015-11-25 12:01:00 +00002// RUN: %clang_cc1 -triple=x86_64-pc-win32 -fms-compatibility -emit-pch -o %t %s
3// RUN: %clang_cc1 -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
Alexey Bataev69103472015-10-14 04:05:42 +00008
9class Test1 {
10private:
11 int x_;
Alexey Bataevf7630272015-11-25 12:01:00 +000012 double y_;
Alexey Bataev69103472015-10-14 04:05:42 +000013
14public:
15 Test1(int x) : x_(x) {}
16 __declspec(property(get = get_x)) int X;
17 int get_x() const { return x_; }
18 static Test1 *GetTest1() { return new Test1(10); }
19};
20
Alexey Bataevf7630272015-11-25 12:01:00 +000021class S {
22public:
23 __declspec(property(get=GetX,put=PutX)) int x[];
24 int GetX(int i, int j) { return i+j; }
25 void PutX(int i, int j, int k) { j = i = k; }
26};
27
28template <typename T>
29class St {
30public:
31 __declspec(property(get=GetX,put=PutX)) T x[];
32 T GetX(T i, T j) { return i+j; }
33 T GetX() { return 0; }
Alexey Bataev60520e22015-12-10 04:38:18 +000034 T PutX(T i, T j, T k) { return j = i = k; }
Alexey Bataevf7630272015-11-25 12:01:00 +000035 __declspec(property(get=GetY,put=PutY)) T y[];
36 char GetY(char i, Test1 j) { return i+j.get_x(); }
37 void PutY(char i, int j, double k) { j = i = k; }
38};
39
40template <typename T>
41void 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
49int idx() { return 7; }
50
Alexey Bataev69103472015-10-14 04:05:42 +000051// CHECK-LABEL: main
52int main(int argc, char **argv) {
Alexey Bataevf7630272015-11-25 12:01:00 +000053 Test1 t(argc);
54 S *p1 = 0;
55 St<float> *p2 = 0;
56 // CHECK: call i32 @"\01?GetX@S@@QEAAHHH@Z"(%class.S* %{{.+}}, i32 223, i32 11)
57 int j = p1->x[223][11];
58 // CHECK: [[J:%.+]] = load i32, i32* %
59 // CHECK-NEXT: call void @"\01?PutX@S@@QEAAXHHH@Z"(%class.S* %{{.+}}, i32 23, i32 1, i32 [[J]])
60 p1->x[23][1] = j;
61 // CHECK: call float @"\01?GetX@?$St@M@@QEAAMMM@Z"(%class.St* %{{.+}}, float 2.230000e+02, float 1.100000e+01)
62 float j1 = p2->x[223][11];
63 // CHECK: [[J1:%.+]] = load float, float* %
Alexey Bataev60520e22015-12-10 04:38:18 +000064 // CHECK-NEXT: [[CALL:%.+]] = call float @"\01?PutX@?$St@M@@QEAAMMMM@Z"(%class.St* %{{.+}}, float 2.300000e+01, float 1.000000e+00, float [[J1]])
65 // CHECK-NEXT: [[CONV:%.+]] = fptosi float [[CALL]] to i32
66 // CHECK-NEXT: store i32 [[CONV]], i32*
67 argc = p2->x[23][1] = j1;
Alexey Bataevf7630272015-11-25 12:01:00 +000068 // CHECK: [[IDX:%.+]] = call i32 @"\01?idx@@YAHXZ"()
69 // CHECK-NEXT: [[CONV:%.+]] = sitofp i32 [[IDX]] to float
70 // CHECK-NEXT: [[GET:%.+]] = call float @"\01?GetX@?$St@M@@QEAAMMM@Z"(%class.St* %{{.+}}, float [[CONV]], float 1.000000e+00)
71 // CHECK-NEXT: [[INC:%.+]] = fadd float [[GET]], 1.000000e+00
72 // CHECK-NEXT: [[CONV:%.+]] = sitofp i32 [[IDX]] to float
Alexey Bataev60520e22015-12-10 04:38:18 +000073 // CHECK-NEXT: call float @"\01?PutX@?$St@M@@QEAAMMMM@Z"(%class.St* %{{.+}}, float [[CONV]], float 1.000000e+00, float [[INC]])
Alexey Bataevf7630272015-11-25 12:01:00 +000074 ++p2->x[idx()][1];
75 // CHECK: call void @"\01??$foo@H@@YAXHH@Z"(i32 %{{.+}}, i32 %{{.+}})
76 foo(argc, (int)argv[0][0]);
77 // CHECK: [[P2:%.+]] = load %class.St*, %class.St** %
78 // CHECK: [[T_X:%.+]] = call i32 @"\01?get_x@Test1@@QEBAHXZ"(%class.Test1* %{{.+}})
79 // CHECK: [[P1:%.+]] = load %class.S*, %class.S** %
80 // CHECK: [[P1_X_22_33:%.+]] = call i32 @"\01?GetX@S@@QEAAHHH@Z"(%class.S* [[P1]], i32 22, i32 33)
81 // CHECK: [[CAST:%.+]] = sitofp i32 [[P1_X_22_33]] to double
82 // CHECK: [[ARGC:%.+]] = load i32, i32* %
83 // CHECK: [[CAST2:%.+]] = trunc i32 [[T_X]] to i8
84 // CHECK: call void @"\01?PutY@?$St@M@@QEAAXDHN@Z"(%class.St* [[P2]], i8 [[CAST2]], i32 [[ARGC]], double [[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 i32 @"\01?GetX@S@@QEAAHHH@Z"(%class.S* [[P1]], i32 [[ARGC]], i32 0)
91 // CHECK: [[CAST:%.+]] = trunc i32 [[P1_X_ARGC_0]] to i8
92 // CHECK: [[P2_Y_p1_X_ARGC_0_T:%.+]] = call i8 @"\01?GetY@?$St@M@@QEAADDVTest1@@@Z"(%class.St* [[P2_2]], i8 [[CAST]], %class.Test1* %{{.+}})
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
Alexey Bataev60520e22015-12-10 04:38:18 +000098 // CHECK: call float @"\01?PutX@?$St@M@@QEAAMMMM@Z"(%class.St* [[P2_1]], float [[CAST2]], float [[CAST1]], float [[CAST]])
Alexey Bataevf7630272015-11-25 12:01:00 +000099 p2->x[j][j] = p2->y[p1->x[argc][0]][t];
Alexey Bataev69103472015-10-14 04:05:42 +0000100 // CHECK: [[CALL:%.+]] = call %class.Test1* @"\01?GetTest1@Test1@@SAPEAV1@XZ"()
101 // CHECK-NEXT: call i32 @"\01?get_x@Test1@@QEBAHXZ"(%class.Test1* [[CALL]])
102 return Test1::GetTest1()->X;
103}
Alexey Bataevf7630272015-11-25 12:01:00 +0000104
105// CHECK: define linkonce_odr void @"\01??$foo@H@@YAXHH@Z"(i32 %{{.+}}, i32 %{{.+}})
106// CHECK: call i32 @"\01?GetX@?$St@H@@QEAAHHH@Z"(%class.St{{.+}}* [[BAR:%.+]], i32 %{{.+}} i32 %{{.+}})
Alexey Bataev60520e22015-12-10 04:38:18 +0000107// CHECK: call i32 @"\01?PutX@?$St@H@@QEAAHHHH@Z"(%class.St{{.+}}* [[BAR]], i32 %{{.+}}, i32 %{{.+}}, i32 %{{.+}})
Alexey Bataevf7630272015-11-25 12:01:00 +0000108// CHECK: call i32 @"\01?GetX@?$St@H@@QEAAHHH@Z"(%class.St{{.+}}* [[BAR]], i32 %{{.+}} i32 %{{.+}})
109// CHECK: call void @"\01?PutY@?$St@H@@QEAAXDHN@Z"(%class.St{{.+}}* [[BAR]], i8 %{{.+}}, i32 %{{.+}}, double %{{.+}}
110// CHECK: call i32 @"\01?GetX@?$St@H@@QEAAHHH@Z"(%class.St{{.+}}* [[BAR]], i32 %{{.+}} i32 %{{.+}})
111// CHECK: call i8 @"\01?GetY@?$St@H@@QEAADDVTest1@@@Z"(%class.St{{.+}}* [[BAR]], i8 %{{.+}}, %class.Test1* %{{.+}})
Alexey Bataev60520e22015-12-10 04:38:18 +0000112// CHECK: call i32 @"\01?PutX@?$St@H@@QEAAHHHH@Z"(%class.St{{.+}}* [[BAR]], i32 %{{.+}}, i32 %{{.+}}, i32 %{{.+}})
Alexey Bataevf7630272015-11-25 12:01:00 +0000113#endif //HEADER