[Reland][Runtimes] Merge 'compile_commands.json' files from runtimes build (#116303)
[llvm-project.git] / clang / test / CodeGenCXX / microsoft-abi-array-cookies.cpp
blob1cc0e9af571c3a99fe8d50c12a37bc5699344870
1 // RUN: %clang_cc1 -emit-llvm %s -o - -triple=i386-pc-win32 | FileCheck %s
3 struct ClassWithoutDtor {
4 char x;
5 };
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 ptr @"??_U@YAPAXI@Z"(i32 noundef 42)
11 ClassWithoutDtor *array = new ClassWithoutDtor[42];
13 // CHECK: call void @"??_V@YAXPAX@Z"(
14 delete [] array;
18 struct ClassWithDtor {
19 char x;
20 ~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 ptr @"??_U@YAPAXI@Z"(i32 noundef 46)
28 // 46 = 42 + size of cookie (4)
29 // CHECK: store i32 42, ptr [[ALLOCATED]]
30 // CHECK: [[ARRAY:%.*]] = getelementptr inbounds i8, ptr [[ALLOCATED]], i32 4
32 delete [] array;
33 // CHECK: getelementptr inbounds i8, ptr {{%.*}}, i32 -4
36 struct __attribute__((aligned(8))) ClassWithAlignment {
37 // FIXME: replace __attribute__((aligned(8))) with __declspec(align(8)) once
38 // http://llvm.org/bugs/show_bug.cgi?id=12631 is fixed.
39 int *x, *y;
40 ~ClassWithAlignment() {}
43 void check_array_cookies_aligned() {
44 // CHECK: define {{.*}} @"?check_array_cookies_aligned@@YAXXZ"()
45 ClassWithAlignment *array = new ClassWithAlignment[42];
46 // CHECK: [[ALLOCATED:%.*]] = call noalias noundef nonnull ptr @"??_U@YAPAXI@Z"(i32 noundef 344)
47 // 344 = 42*8 + size of cookie (8, due to alignment)
48 // CHECK: store i32 42, ptr [[ALLOCATED]]
49 // CHECK: [[ARRAY:%.*]] = getelementptr inbounds i8, ptr [[ALLOCATED]], i32 8
51 delete [] array;
52 // CHECK: getelementptr inbounds i8, ptr {{.*}}, i32 -8
55 namespace PR23990 {
56 struct S {
57 char x[42];
58 void operator delete[](void *p, __SIZE_TYPE__);
59 // CHECK-LABEL: define dso_local void @"?delete_s@PR23990@@YAXPAUS@1@@Z"(
60 // CHECK: call void @"??_VS@PR23990@@SAXPAXI@Z"(ptr noundef {{.*}}, i32 noundef 42)
62 void delete_s(S *s) { delete[] s; }
65 // CHECK: attributes [[NUW]] = { mustprogress noinline nounwind{{.*}} }