xref: /minix3/external/bsd/llvm/dist/clang/test/CodeGenCXX/microsoft-new.cpp (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1f4a2713aSLionel Sambuc // RUN: %clang_cc1 -triple i686-pc-win32 -fms-compatibility %s -emit-llvm -o - | FileCheck %s
2f4a2713aSLionel Sambuc 
3f4a2713aSLionel Sambuc #include <stddef.h>
4f4a2713aSLionel Sambuc 
5f4a2713aSLionel Sambuc struct arbitrary_t {} arbitrary;
6f4a2713aSLionel Sambuc void *operator new(size_t size, arbitrary_t);
7f4a2713aSLionel Sambuc 
8f4a2713aSLionel Sambuc struct arbitrary2_t {} arbitrary2;
9f4a2713aSLionel Sambuc void *operator new[](size_t size, arbitrary2_t);
10f4a2713aSLionel Sambuc 
11f4a2713aSLionel Sambuc namespace PR13164 {
f()12f4a2713aSLionel Sambuc   void f() {
13f4a2713aSLionel Sambuc 	// MSVC will fall back on the non-array operator new.
14f4a2713aSLionel Sambuc     void *a;
15f4a2713aSLionel Sambuc     int *p = new(arbitrary) int[4];
16*0a6a1f1dSLionel Sambuc     // CHECK: call i8* @"\01??2@YAPAXIUarbitrary_t@@@Z"(i32 16, %struct.arbitrary_t*
17f4a2713aSLionel Sambuc   }
18f4a2713aSLionel Sambuc 
19f4a2713aSLionel Sambuc   struct S {
20f4a2713aSLionel Sambuc     void *operator new[](size_t size, arbitrary_t);
21f4a2713aSLionel Sambuc   };
22f4a2713aSLionel Sambuc 
g()23f4a2713aSLionel Sambuc   void g() {
24f4a2713aSLionel Sambuc     S *s = new(arbitrary) S[2];
25*0a6a1f1dSLionel Sambuc     // CHECK: call i8* @"\01??_US@PR13164@@SAPAXIUarbitrary_t@@@Z"(i32 2, %struct.arbitrary_t*
26f4a2713aSLionel Sambuc     S *s1 = new(arbitrary) S;
27*0a6a1f1dSLionel Sambuc     // CHECK: call i8* @"\01??2@YAPAXIUarbitrary_t@@@Z"(i32 1, %struct.arbitrary_t*
28f4a2713aSLionel Sambuc   }
29f4a2713aSLionel Sambuc 
30f4a2713aSLionel Sambuc   struct T {
31f4a2713aSLionel Sambuc     void *operator new(size_t size, arbitrary2_t);
32f4a2713aSLionel Sambuc   };
33f4a2713aSLionel Sambuc 
h()34f4a2713aSLionel Sambuc   void h() {
35f4a2713aSLionel Sambuc     // This should still call the global operator new[].
36f4a2713aSLionel Sambuc     T *t = new(arbitrary2) T[2];
37*0a6a1f1dSLionel Sambuc     // CHECK: call i8* @"\01??_U@YAPAXIUarbitrary2_t@@@Z"(i32 2, %struct.arbitrary2_t*
38f4a2713aSLionel Sambuc   }
39f4a2713aSLionel Sambuc }
40