66 lines · cpp
1// RUN: %clang_cc1 -emit-llvm %s -o - -triple=i386-pc-win32 | FileCheck %s2 3struct ClassWithoutDtor {4 char x;5};6 7void 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 18struct ClassWithDtor {19 char x;20 ~ClassWithDtor() {}21};22 23void 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 431 32 delete [] array;33// CHECK: getelementptr inbounds i8, ptr {{%.*}}, i32 -434}35 36struct __attribute__((aligned(8))) ClassWithAlignment {37 // FIXME: replace __attribute__((aligned(8))) with __declspec(align(8)) once38 // http://llvm.org/bugs/show_bug.cgi?id=12631 is fixed.39 int *x, *y;40 ~ClassWithAlignment() {}41};42 43void 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 850 51 delete [] array;52// CHECK: getelementptr inbounds i8, ptr {{.*}}, i32 -853}54 55namespace PR23990 {56struct 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};62void delete_s(S *s) { delete[] s; }63}64 65// CHECK: attributes [[NUW]] = { mustprogress noinline nounwind{{.*}} }66