summaryrefslogtreecommitdiffstats
path: root/compiler-rt/test
diff options
context:
space:
mode:
authorKuba Brecka <kuba.brecka@gmail.com>2016-04-14 09:05:19 +0000
committerKuba Brecka <kuba.brecka@gmail.com>2016-04-14 09:05:19 +0000
commit173c690a618287d06fe7f29175675af12dbe3a6a (patch)
treeb93fb0ac8fe2803234dcc1f0dd66ef7144608837 /compiler-rt/test
parent7aab6488310361f87e884d030aaa982ce825f957 (diff)
downloadbcm5719-llvm-173c690a618287d06fe7f29175675af12dbe3a6a.tar.gz
bcm5719-llvm-173c690a618287d06fe7f29175675af12dbe3a6a.zip
[tsan] Fix size reporting for OS X zone allocator with 0-sized allocations
The custom zone implementation for OS X must not return 0 (even for 0-sized allocations). Returning 0 indicates that the pointer doesn't belong to the zone. This can break existing applications. The underlaying allocator allocates 1 byte for 0-sized allocations anyway, so returning 1 in this case is okay. Differential Revision: http://reviews.llvm.org/D19100 llvm-svn: 266283
Diffstat (limited to 'compiler-rt/test')
-rw-r--r--compiler-rt/test/tsan/Darwin/malloc_size.mm23
1 files changed, 23 insertions, 0 deletions
diff --git a/compiler-rt/test/tsan/Darwin/malloc_size.mm b/compiler-rt/test/tsan/Darwin/malloc_size.mm
new file mode 100644
index 00000000000..da1830529dd
--- /dev/null
+++ b/compiler-rt/test/tsan/Darwin/malloc_size.mm
@@ -0,0 +1,23 @@
+// Test that malloc_zone_from_ptr returns a valid zone for a 0-sized allocation.
+
+// RUN: %clang_tsan %s -o %t -framework Foundation
+// RUN: %run %t 2>&1 | FileCheck %s
+
+#import <Foundation/Foundation.h>
+#include <malloc/malloc.h>
+
+int main() {
+ void *p = malloc(0);
+
+ size_t s = malloc_size(p);
+ printf("size = 0x%zx\n", s);
+
+ malloc_zone_t *z = malloc_zone_from_ptr(p);
+ if (z)
+ printf("z = %p\n", z);
+ else
+ printf("no zone\n");
+}
+
+// CHECK: z = 0x{{[0-9a-f]+}}
+// CHECK-NOT: no zone
OpenPOWER on IntegriCloud