xref: /llvm-project/clang/test/CodeGenCXX/ms-property-new.cpp (revision af0ee617fc5f69051297b0c23f8c818b20f02c3a)
1 // RUN: %clang_cc1 -emit-llvm -triple=x86_64-pc-win32 -fms-compatibility %s -o - | FileCheck %s
2 // 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
8 
9 struct S {
GetXS10   int GetX() { return 42; }
11   __declspec(property(get=GetX)) int x;
12 
GetYS13   int GetY(int i, int j) { return i+j; }
14   __declspec(property(get=GetY)) int y[];
15 
16   void* operator new(__SIZE_TYPE__, int);
17 };
18 
19 template <typename T>
20 struct TS {
GetTTS21   T GetT() { return T(); }
22   __declspec(property(get=GetT)) T t;
23 
GetRTS24   T GetR(T i, T j) { return i+j; }
25   __declspec(property(get=GetR)) T r[];
26 };
27 
28 // CHECK-LABEL: main
main(int argc,char ** argv)29 int main(int argc, char **argv) {
30   S *s;
31   TS<double> *ts;
32 
33   // CHECK: [[X:%.+]] = call noundef i32 @"?GetX@S@@QEAAHXZ"(ptr {{[^,]*}} %{{.+}})
34   // CHECK-NEXT: call noundef ptr @"??2S@@SAPEAX_KH@Z"(i64 noundef 1, i32 noundef [[X]])
35   new (s->x) S;
36 
37   // CHECK: [[Y:%.+]] = call noundef i32 @"?GetY@S@@QEAAHHH@Z"(ptr {{[^,]*}} %{{.+}}, i32 noundef 1, i32 noundef 2)
38   // CHECK-NEXT: call noundef ptr @"??2S@@SAPEAX_KH@Z"(i64 noundef 1, i32 noundef [[Y]])
39   new ((s->y)[1][2]) S;
40 
41   // CHECK: [[T:%.+]] = call noundef double @"?GetT@?$TS@N@@QEAANXZ"(ptr {{[^,]*}} %{{.+}})
42   // CHECK-NEXT: [[TI:%.+]] = fptosi double [[T]] to i32
43   // CHECK-NEXT: call noundef ptr @"??2S@@SAPEAX_KH@Z"(i64 noundef 1, i32 noundef [[TI]])
44   new (ts->t) S;
45 
46   // CHECK: [[R:%.+]] = call noundef double @"?GetR@?$TS@N@@QEAANNN@Z"(ptr {{[^,]*}} %{{.+}}, double {{[^,]*}}, double {{[^,]*}})
47   // CHECK-NEXT: [[RI:%.+]] = fptosi double [[R]] to i32
48   // CHECK-NEXT: call noundef ptr @"??2S@@SAPEAX_KH@Z"(i64 noundef 1, i32 noundef [[RI]])
49   new ((ts->r)[1][2]) S;
50 }
51 
52 #endif
53