1 // RUN: %clang_cc1 -emit-llvm %s -o - -triple=i386-pc-win32 | FileCheck %s
3 struct ClassWithoutDtor
{
7 void check_array_no_cookies() {
8 // CHECK: define dso_local void @"?check_array_no_cookies@@YAXXZ"() [[NUW:#[0-9]+]]
10 // CHECK: call noalias noundef nonnull i8* @"??_U@YAPAXI@Z"(i32 noundef 42)
11 ClassWithoutDtor
*array
= new ClassWithoutDtor
[42];
13 // CHECK: call void @"??_V@YAXPAX@Z"(
18 struct ClassWithDtor
{
23 void check_array_cookies_simple() {
24 // CHECK: define {{.*}} @"?check_array_cookies_simple@@YAXXZ"()
26 ClassWithDtor
*array
= new ClassWithDtor
[42];
27 // CHECK: [[ALLOCATED:%.*]] = call noalias noundef nonnull i8* @"??_U@YAPAXI@Z"(i32 noundef 46)
28 // 46 = 42 + size of cookie (4)
29 // CHECK: [[COOKIE:%.*]] = bitcast i8* [[ALLOCATED]] to i32*
30 // CHECK: store i32 42, i32* [[COOKIE]]
31 // CHECK: [[ARRAY:%.*]] = getelementptr inbounds i8, i8* [[ALLOCATED]], i32 4
32 // CHECK: bitcast i8* [[ARRAY]] to [[CLASS:%.*]]*
35 // CHECK: [[ARRAY_AS_CHAR:%.*]] = bitcast [[CLASS]]* {{%.*}} to i8*
36 // CHECK: getelementptr inbounds i8, i8* [[ARRAY_AS_CHAR]], i32 -4
39 struct __attribute__((aligned(8))) ClassWithAlignment
{
40 // FIXME: replace __attribute__((aligned(8))) with __declspec(align(8)) once
41 // http://llvm.org/bugs/show_bug.cgi?id=12631 is fixed.
43 ~ClassWithAlignment() {}
46 void check_array_cookies_aligned() {
47 // CHECK: define {{.*}} @"?check_array_cookies_aligned@@YAXXZ"()
48 ClassWithAlignment
*array
= new ClassWithAlignment
[42];
49 // CHECK: [[ALLOCATED:%.*]] = call noalias noundef nonnull i8* @"??_U@YAPAXI@Z"(i32 noundef 344)
50 // 344 = 42*8 + size of cookie (8, due to alignment)
51 // CHECK: [[COOKIE:%.*]] = bitcast i8* [[ALLOCATED]] to i32*
52 // CHECK: store i32 42, i32* [[COOKIE]]
53 // CHECK: [[ARRAY:%.*]] = getelementptr inbounds i8, i8* [[ALLOCATED]], i32 8
54 // CHECK: bitcast i8* [[ARRAY]] to [[CLASS:%.*]]*
57 // CHECK: [[ARRAY_AS_CHAR:%.*]] = bitcast [[CLASS]]*
58 // CHECK: getelementptr inbounds i8, i8* [[ARRAY_AS_CHAR]], i32 -8
64 void operator delete[](void *p
, __SIZE_TYPE__
);
65 // CHECK-LABEL: define dso_local void @"?delete_s@PR23990@@YAXPAUS@1@@Z"(
66 // CHECK: call void @"??_VS@PR23990@@SAXPAXI@Z"(i8* noundef {{.*}}, i32 noundef 42)
68 void delete_s(S
*s
) { delete[] s
; }
71 // CHECK: attributes [[NUW]] = { mustprogress noinline nounwind{{.*}} }