2014-01-15 03:35:09 +08:00
|
|
|
// RUN: %clang_cc1 -emit-llvm %s -o - -triple=i386-pc-win32 | FileCheck %s
|
2012-05-01 13:23:51 +08:00
|
|
|
|
|
|
|
struct ClassWithoutDtor {
|
|
|
|
char x;
|
|
|
|
};
|
|
|
|
|
|
|
|
void check_array_no_cookies() {
|
2013-03-01 06:49:57 +08:00
|
|
|
// CHECK: define void @"\01?check_array_no_cookies@@YAXXZ"() [[NUW:#[0-9]+]]
|
2012-05-01 13:23:51 +08:00
|
|
|
|
|
|
|
// CHECK: call noalias i8* @"\01??_U@YAPAXI@Z"(i32 42)
|
|
|
|
ClassWithoutDtor *array = new ClassWithoutDtor[42];
|
|
|
|
|
|
|
|
// CHECK: call void @"\01??_V@YAXPAX@Z"(
|
|
|
|
delete [] array;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
struct ClassWithDtor {
|
|
|
|
char x;
|
|
|
|
~ClassWithDtor() {}
|
|
|
|
};
|
|
|
|
|
|
|
|
void check_array_cookies_simple() {
|
|
|
|
// CHECK: define {{.*}} @"\01?check_array_cookies_simple@@YAXXZ"()
|
|
|
|
|
|
|
|
ClassWithDtor *array = new ClassWithDtor[42];
|
|
|
|
// CHECK: [[ALLOCATED:%.*]] = call noalias i8* @"\01??_U@YAPAXI@Z"(i32 46)
|
|
|
|
// 46 = 42 + size of cookie (4)
|
|
|
|
// CHECK: [[COOKIE:%.*]] = bitcast i8* [[ALLOCATED]] to i32*
|
|
|
|
// CHECK: store i32 42, i32* [[COOKIE]]
|
2015-02-28 03:18:17 +08:00
|
|
|
// CHECK: [[ARRAY:%.*]] = getelementptr inbounds i8, i8* [[ALLOCATED]], i64 4
|
2012-05-01 13:29:32 +08:00
|
|
|
// CHECK: bitcast i8* [[ARRAY]] to [[CLASS:%.*]]*
|
2012-05-01 13:23:51 +08:00
|
|
|
|
|
|
|
delete [] array;
|
2012-05-01 13:29:32 +08:00
|
|
|
// CHECK: [[ARRAY_AS_CHAR:%.*]] = bitcast [[CLASS]]* {{%.*}} to i8*
|
2015-02-28 03:18:17 +08:00
|
|
|
// CHECK: getelementptr inbounds i8, i8* [[ARRAY_AS_CHAR]], i64 -4
|
2012-05-01 13:23:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
struct __attribute__((aligned(8))) ClassWithAlignment {
|
|
|
|
// FIXME: replace __attribute__((aligned(8))) with __declspec(align(8)) once
|
|
|
|
// http://llvm.org/bugs/show_bug.cgi?id=12631 is fixed.
|
|
|
|
int *x, *y;
|
|
|
|
~ClassWithAlignment() {}
|
|
|
|
};
|
|
|
|
|
|
|
|
void check_array_cookies_aligned() {
|
|
|
|
// CHECK: define {{.*}} @"\01?check_array_cookies_aligned@@YAXXZ"()
|
|
|
|
ClassWithAlignment *array = new ClassWithAlignment[42];
|
|
|
|
// CHECK: [[ALLOCATED:%.*]] = call noalias i8* @"\01??_U@YAPAXI@Z"(i32 344)
|
2012-05-01 13:29:32 +08:00
|
|
|
// 344 = 42*8 + size of cookie (8, due to alignment)
|
2012-05-01 13:23:51 +08:00
|
|
|
// CHECK: [[COOKIE:%.*]] = bitcast i8* [[ALLOCATED]] to i32*
|
|
|
|
// CHECK: store i32 42, i32* [[COOKIE]]
|
2015-02-28 03:18:17 +08:00
|
|
|
// CHECK: [[ARRAY:%.*]] = getelementptr inbounds i8, i8* [[ALLOCATED]], i64 8
|
2012-05-01 13:29:32 +08:00
|
|
|
// CHECK: bitcast i8* [[ARRAY]] to [[CLASS:%.*]]*
|
2012-05-01 13:23:51 +08:00
|
|
|
|
|
|
|
delete [] array;
|
2012-05-01 19:13:04 +08:00
|
|
|
// CHECK: [[ARRAY_AS_CHAR:%.*]] = bitcast [[CLASS]]*
|
2015-02-28 03:18:17 +08:00
|
|
|
// CHECK: getelementptr inbounds i8, i8* [[ARRAY_AS_CHAR]], i64 -8
|
2012-05-01 13:23:51 +08:00
|
|
|
}
|
2013-02-20 15:22:19 +08:00
|
|
|
|
2013-03-01 06:49:57 +08:00
|
|
|
// CHECK: attributes [[NUW]] = { nounwind{{.*}} }
|