John McCall | e2b45e2 | 2012-05-01 05:23:51 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -emit-llvm %s -o - -cxx-abi microsoft -triple=i386-pc-win32 | FileCheck %s |
| 2 | |
| 3 | struct ClassWithoutDtor { |
| 4 | char x; |
| 5 | }; |
| 6 | |
| 7 | void check_array_no_cookies() { |
| 8 | // CHECK: define void @"\01?check_array_no_cookies@@YAXXZ"() nounwind |
| 9 | |
| 10 | // CHECK: call noalias i8* @"\01??_U@YAPAXI@Z"(i32 42) |
| 11 | ClassWithoutDtor *array = new ClassWithoutDtor[42]; |
| 12 | |
| 13 | // CHECK: call void @"\01??_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 {{.*}} @"\01?check_array_cookies_simple@@YAXXZ"() |
| 25 | |
| 26 | ClassWithDtor *array = new ClassWithDtor[42]; |
| 27 | // CHECK: [[ALLOCATED:%.*]] = call noalias i8* @"\01??_U@YAPAXI@Z"(i32 46) |
| 28 | // 46 = 42 + size of cookie (4) |
| 29 | // CHECK: [[COOKIE:%.*]] = bitcast i8* [[ALLOCATED]] to i32* |
| 30 | // CHECK: store i32 42, i32* [[COOKIE]] |
John McCall | 2e7651d | 2012-05-01 05:29:32 +0000 | [diff] [blame] | 31 | // CHECK: [[ARRAY:%.*]] = getelementptr inbounds i8* [[ALLOCATED]], i64 4 |
| 32 | // CHECK: bitcast i8* [[ARRAY]] to [[CLASS:%.*]]* |
John McCall | e2b45e2 | 2012-05-01 05:23:51 +0000 | [diff] [blame] | 33 | |
| 34 | delete [] array; |
John McCall | 2e7651d | 2012-05-01 05:29:32 +0000 | [diff] [blame] | 35 | // CHECK: [[ARRAY_AS_CHAR:%.*]] = bitcast [[CLASS]]* {{%.*}} to i8* |
| 36 | // CHECK: getelementptr inbounds i8* [[ARRAY_AS_CHAR]], i64 -4 |
John McCall | e2b45e2 | 2012-05-01 05:23:51 +0000 | [diff] [blame] | 37 | } |
| 38 | |
| 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. |
| 42 | int *x, *y; |
| 43 | ~ClassWithAlignment() {} |
| 44 | }; |
| 45 | |
| 46 | void check_array_cookies_aligned() { |
| 47 | // CHECK: define {{.*}} @"\01?check_array_cookies_aligned@@YAXXZ"() |
| 48 | ClassWithAlignment *array = new ClassWithAlignment[42]; |
| 49 | // CHECK: [[ALLOCATED:%.*]] = call noalias i8* @"\01??_U@YAPAXI@Z"(i32 344) |
John McCall | 2e7651d | 2012-05-01 05:29:32 +0000 | [diff] [blame] | 50 | // 344 = 42*8 + size of cookie (8, due to alignment) |
John McCall | e2b45e2 | 2012-05-01 05:23:51 +0000 | [diff] [blame] | 51 | // CHECK: [[COOKIE:%.*]] = bitcast i8* [[ALLOCATED]] to i32* |
| 52 | // CHECK: store i32 42, i32* [[COOKIE]] |
John McCall | 2e7651d | 2012-05-01 05:29:32 +0000 | [diff] [blame] | 53 | // CHECK: [[ARRAY:%.*]] = getelementptr inbounds i8* [[ALLOCATED]], i64 8 |
| 54 | // CHECK: bitcast i8* [[ARRAY]] to [[CLASS:%.*]]* |
John McCall | e2b45e2 | 2012-05-01 05:23:51 +0000 | [diff] [blame] | 55 | |
| 56 | delete [] array; |
NAKAMURA Takumi | 287ab9f | 2012-05-01 11:13:04 +0000 | [diff] [blame] | 57 | // CHECK: [[ARRAY_AS_CHAR:%.*]] = bitcast [[CLASS]]* |
John McCall | 2e7651d | 2012-05-01 05:29:32 +0000 | [diff] [blame] | 58 | // CHECK: getelementptr inbounds i8* [[ARRAY_AS_CHAR]], i64 -8 |
John McCall | e2b45e2 | 2012-05-01 05:23:51 +0000 | [diff] [blame] | 59 | } |