[PATCH] D19100: [tsan] Fix size reporting for OS X zone allocator with 0-sized allocations

Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 14 02:10:56 PDT 2016


This revision was automatically updated to reflect the committed changes.
Closed by commit rL266283: [tsan] Fix size reporting for OS X zone allocator with 0-sized allocations (authored by kuba.brecka).

Changed prior to commit:
  http://reviews.llvm.org/D19100?vs=53670&id=53675#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D19100

Files:
  compiler-rt/trunk/lib/tsan/rtl/tsan_malloc_mac.cc
  compiler-rt/trunk/test/tsan/Darwin/malloc_size.mm

Index: compiler-rt/trunk/lib/tsan/rtl/tsan_malloc_mac.cc
===================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_malloc_mac.cc
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_malloc_mac.cc
@@ -53,7 +53,8 @@
   SCOPED_INTERCEPTOR_RAW(free, ptr); \
   user_free(thr, pc, ptr)
 #define COMMON_MALLOC_SIZE(ptr) \
-  uptr size = user_alloc_usable_size(ptr);
+  uptr size = user_alloc_usable_size(ptr); \
+  if (size == 0) size = 1;
 #define COMMON_MALLOC_FILL_STATS(zone, stats)
 #define COMMON_MALLOC_REPORT_UNKNOWN_REALLOC(ptr, zone_ptr, zone_name) \
   (void)zone_name; \
Index: compiler-rt/trunk/test/tsan/Darwin/malloc_size.mm
===================================================================
--- compiler-rt/trunk/test/tsan/Darwin/malloc_size.mm
+++ compiler-rt/trunk/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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D19100.53675.patch
Type: text/x-patch
Size: 1386 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160414/ed48d6f0/attachment.bin>


More information about the llvm-commits mailing list