| 1 |
// RUN: %clang_cc1 -emit-llvm %s -o - -triple=i386-pc-win32 | FileCheck %s |
| 2 |
|
| 3 |
struct ClassWithoutDtor { |
| 4 |
char x; |
| 5 |
}; |
| 6 |
|
| 7 |
void check_array_no_cookies() { |
| 8 |
// CHECK: define dso_local void @"?check_array_no_cookies@@YAXXZ"() [[NUW:#[0-9]+]] |
| 9 |
|
| 10 |
// CHECK: call noalias noundef nonnull ptr @"??_U@YAPAXI@Z"(i32 noundef 42) |
| 11 |
ClassWithoutDtor *array = new ClassWithoutDtor[42]; |
| 12 |
|
| 13 |
// CHECK: call void @"??_V@YAXPAX@Z"( |
| 14 |
delete [] array; |
| 15 |
|
| 16 |
} |
| 17 |
|
| 18 |
struct ClassWithDtor { |
| 19 |
char x; |
| 20 |
~ClassWithDtor() {} |
| 21 |
}; |
| 22 |
|
| 23 |
void check_array_cookies_simple() { |
| 24 |
// CHECK: define {{.*}} @"?check_array_cookies_simple@@YAXXZ"() |
| 25 |
|
| 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 |
| 31 |
|
| 32 |
delete [] array; |
| 33 |
// CHECK: getelementptr inbounds i8, ptr {{%.*}}, i32 -4 |
| 34 |
} |
| 35 |
|
| 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() {} |
| 41 |
}; |
| 42 |
|
| 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 |
| 50 |
|
| 51 |
delete [] array; |
| 52 |
// CHECK: getelementptr inbounds i8, ptr {{.*}}, i32 -8 |
| 53 |
} |
| 54 |
|
| 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) |
| 61 |
}; |
| 62 |
void delete_s(S *s) { delete[] s; } |
| 63 |
} |
| 64 |
|
| 65 |
// CHECK: attributes [[NUW]] = { mustprogress noinline nounwind{{.*}} } |