summaryrefslogtreecommitdiffstats
path: root/compiler-rt/test
diff options
context:
space:
mode:
authorKuba Brecka <kuba.brecka@gmail.com>2016-04-30 07:14:41 +0000
committerKuba Brecka <kuba.brecka@gmail.com>2016-04-30 07:14:41 +0000
commit9ccde5ace4c1905f328ca48a3207e2b5ba756533 (patch)
treed580500fb539fae93c9f53498197bb598e701655 /compiler-rt/test
parenteb5bd02a7ec2c0a5d10d8f68c5c40c00776824fb (diff)
downloadbcm5719-llvm-9ccde5ace4c1905f328ca48a3207e2b5ba756533.tar.gz
bcm5719-llvm-9ccde5ace4c1905f328ca48a3207e2b5ba756533.zip
[tsan] Return 0 from malloc_size for non-malloc'd pointers
In http://reviews.llvm.org/D19100, I introduced a bug: On OS X, existing programs rely on malloc_size() to detect whether a pointer comes from heap memory (malloc_size returns non-zero) or not. We have to distinguish between a zero-sized allocation (where we need to return 1 from malloc_size, due to other binary compatibility reasons, see http://reviews.llvm.org/D19100), and pointers that are not returned from malloc at all. Differential Revision: http://reviews.llvm.org/D19653 llvm-svn: 268157
Diffstat (limited to 'compiler-rt/test')
-rw-r--r--compiler-rt/test/tsan/Darwin/malloc_size.mm54
1 files changed, 43 insertions, 11 deletions
diff --git a/compiler-rt/test/tsan/Darwin/malloc_size.mm b/compiler-rt/test/tsan/Darwin/malloc_size.mm
index da1830529dd..3d3629b73e7 100644
--- a/compiler-rt/test/tsan/Darwin/malloc_size.mm
+++ b/compiler-rt/test/tsan/Darwin/malloc_size.mm
@@ -6,18 +6,50 @@
#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);
+int some_global;
+void describe_zone(void *p) {
malloc_zone_t *z = malloc_zone_from_ptr(p);
- if (z)
- printf("z = %p\n", z);
- else
- printf("no zone\n");
+ if (z) {
+ fprintf(stderr, "zone = %p\n", z);
+ } else {
+ fprintf(stderr, "zone = no zone\n");
+ }
}
-// CHECK: z = 0x{{[0-9a-f]+}}
-// CHECK-NOT: no zone
+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
+}
OpenPOWER on IntegriCloud