summaryrefslogtreecommitdiffstats
path: root/test/CodeGenCXX/microsoft-abi-array-cookies.cpp
diff options
context:
space:
mode:
authorJohn McCall <rjmccall@apple.com>2012-05-01 05:23:51 +0000
committerJohn McCall <rjmccall@apple.com>2012-05-01 05:23:51 +0000
commite2b45e2a43ae46bc00026b63ba7c04ef2b78c3ff (patch)
tree8e567b4b7bc27ee09e141d3a383c8e66d48e49ff /test/CodeGenCXX/microsoft-abi-array-cookies.cpp
parent95109d2eb6f3670e8558868429f2a622b05e7d4f (diff)
Refactor the C++ ABI code a little bit to take advantage of
what I'm going to treat as basically universal properties of array-cookie code. Implement MS array cookies on top of that. Based on a patch by Timur Iskhodzhanov! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@155886 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/CodeGenCXX/microsoft-abi-array-cookies.cpp')
-rw-r--r--test/CodeGenCXX/microsoft-abi-array-cookies.cpp59
1 files changed, 59 insertions, 0 deletions
diff --git a/test/CodeGenCXX/microsoft-abi-array-cookies.cpp b/test/CodeGenCXX/microsoft-abi-array-cookies.cpp
new file mode 100644
index 0000000000..26caa7a8a5
--- /dev/null
+++ b/test/CodeGenCXX/microsoft-abi-array-cookies.cpp
@@ -0,0 +1,59 @@
+// RUN: %clang_cc1 -emit-llvm %s -o - -cxx-abi microsoft -triple=i386-pc-win32 | FileCheck %s
+
+struct ClassWithoutDtor {
+ char x;
+};
+
+void check_array_no_cookies() {
+// CHECK: define void @"\01?check_array_no_cookies@@YAXXZ"() nounwind
+
+// 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]]
+// CHECK: [[ARRAY:%.*]] = getelementptr inbounds i8* [[ALLOCATED]], i{{[0-9]+}} 4
+// CHECK: bitcast i8* [[ARRAY]] to %struct.ClassWithDtor*
+
+ delete [] array;
+// CHECK: [[ARRAY_AS_CHAR:%.*]] = bitcast %struct.ClassWithDtor* %3 to i8*
+// CHECK: getelementptr inbounds i8* [[ARRAY_AS_CHAR]], i{{[0-9]+}} -4
+}
+
+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)
+// 344 = 42*8 + size of cookie (8, due to aligment)
+// CHECK: [[COOKIE:%.*]] = bitcast i8* [[ALLOCATED]] to i32*
+// CHECK: store i32 42, i32* [[COOKIE]]
+// CHECK: [[ARRAY:%.*]] = getelementptr inbounds i8* [[ALLOCATED]], i{{[0-9]+}} 8
+// CHECK: bitcast i8* [[ARRAY]] to %struct.ClassWithAlignment*
+
+ delete [] array;
+// CHECK: [[ARRAY_AS_CHAR:%.*]] = bitcast %struct.ClassWithAlignment* %3 to i8*
+// CHECK: getelementptr inbounds i8* [[ARRAY_AS_CHAR]], i{{[0-9]+}} -8
+}