summaryrefslogtreecommitdiffstats
path: root/clang/test/CodeGen/object-size.cpp
diff options
context:
space:
mode:
authorGeorge Burgess IV <george.burgess.iv@gmail.com>2015-09-04 22:36:18 +0000
committerGeorge Burgess IV <george.burgess.iv@gmail.com>2015-09-04 22:36:18 +0000
commitb40cd567c3c1caf16e29c34829071e0182e5c5bd (patch)
tree872b1d20d5085e3b6c65d4823bc05c77bd09c099 /clang/test/CodeGen/object-size.cpp
parent3baf9c8ace1d2728086f7cb2a4de2f39d4b5442d (diff)
downloadbcm5719-llvm-b40cd567c3c1caf16e29c34829071e0182e5c5bd.tar.gz
bcm5719-llvm-b40cd567c3c1caf16e29c34829071e0182e5c5bd.zip
Fix a bug in __builtin_object_size cast removal
Apparently there are many cast kinds that may cause implicit pointer arithmetic to happen. In light of this, the cast ignoring logic introduced in r246877 has been changed to only ignore a small set of cast kinds, and a test for this behavior has been added. Thanks to Richard for catching this before it became a bug report. :) llvm-svn: 246890
Diffstat (limited to 'clang/test/CodeGen/object-size.cpp')
-rw-r--r--clang/test/CodeGen/object-size.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/clang/test/CodeGen/object-size.cpp b/clang/test/CodeGen/object-size.cpp
new file mode 100644
index 00000000000..1c9d1ae945d
--- /dev/null
+++ b/clang/test/CodeGen/object-size.cpp
@@ -0,0 +1,30 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin -emit-llvm -o - %s | FileCheck %s
+
+// C++-specific tests for __builtin_object_size
+
+int gi;
+
+// CHECK-LABEL: define void @_Z5test1v()
+void test1() {
+ // Guaranteeing that our cast removal logic doesn't break more interesting
+ // cases.
+ struct A { int a; };
+ struct B { int b; };
+ struct C: public A, public B {};
+
+ C c;
+
+ // CHECK: store i32 8
+ gi = __builtin_object_size(&c, 0);
+ // CHECK: store i32 8
+ gi = __builtin_object_size((A*)&c, 0);
+ // CHECK: store i32 4
+ gi = __builtin_object_size((B*)&c, 0);
+
+ // CHECK: store i32 8
+ gi = __builtin_object_size((char*)&c, 0);
+ // CHECK: store i32 8
+ gi = __builtin_object_size((char*)(A*)&c, 0);
+ // CHECK: store i32 4
+ gi = __builtin_object_size((char*)(B*)&c, 0);
+}
OpenPOWER on IntegriCloud