diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2016-07-23 20:45:36 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2016-07-23 20:45:36 +0000 |
commit | 6f08730ec5f639f05f2f15354171e4a3c9af9dc1 (patch) | |
tree | 7374e9d4448083010ada98d17976199c7e945d47 /test/tsan/Darwin/malloc_size.mm | |
parent | c003a57e2e4a1ad9be0338806bc1038b6987155f (diff) | |
download | src-6f08730ec5f639f05f2f15354171e4a3c9af9dc1.tar.gz src-6f08730ec5f639f05f2f15354171e4a3c9af9dc1.zip |
Vendor import of compiler-rt release_39 branch r276489:vendor/compiler-rt/compiler-rt-release_39-r276489
Notes
Notes:
svn path=/vendor/compiler-rt/dist/; revision=303235
svn path=/vendor/compiler-rt/compiler-rt-release_39-r276489/; revision=303236; tag=vendor/compiler-rt/compiler-rt-release_39-r276489
Diffstat (limited to 'test/tsan/Darwin/malloc_size.mm')
-rw-r--r-- | test/tsan/Darwin/malloc_size.mm | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/test/tsan/Darwin/malloc_size.mm b/test/tsan/Darwin/malloc_size.mm new file mode 100644 index 000000000000..485d85bba4f8 --- /dev/null +++ b/test/tsan/Darwin/malloc_size.mm @@ -0,0 +1,57 @@ +// 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 + +#include <malloc/malloc.h> +#include <stdio.h> +#include <stdlib.h> +#include <sys/mman.h> + +int some_global; + +void describe_zone(void *p) { + malloc_zone_t *z = malloc_zone_from_ptr(p); + if (z) { + fprintf(stderr, "zone = %p\n", z); + } else { + fprintf(stderr, "zone = no zone\n"); + } +} + +int main() { + void *p; + size_t s; + + p = malloc(0x40); + s = malloc_size(p); + fprintf(stderr, "size = 0x%zx\n", s); + // CHECK: size = 0x40 + describe_zone(p); + // CHECK: zone = 0x{{[0-9a-f]+}} + + p = malloc(0); + s = malloc_size(p); + fprintf(stderr, "size = 0x%zx\n", s); + // CHECK: size = 0x1 + describe_zone(p); + // CHECK: zone = 0x{{[0-9a-f]+}} + + p = &some_global; + s = malloc_size(p); + fprintf(stderr, "size = 0x%zx\n", s); + // CHECK: size = 0x0 + describe_zone(p); + // CHECK: zone = no zone + + p = mmap(0, 0x1000, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANON, -1, 0); + if (!p) { + fprintf(stderr, "mmap failed\n"); + exit(1); + } + s = malloc_size(p); + fprintf(stderr, "size = 0x%zx\n", s); + // CHECK: size = 0x0 + describe_zone(p); + // CHECK: zone = no zone +} |