1 // RUN: %clangxx %s -o %t && %run %t 1234
2 // RUN: %clangxx %s -o %t && %run %t 5678910
8 #include <sanitizer/allocator_interface.h>
14 auto allocated_bytes_before
= __sanitizer_get_current_allocated_bytes();
15 int *p
= (int *)malloc(size
);
16 assert(__sanitizer_get_estimated_allocated_size(size
) >= size
);
17 assert(__sanitizer_get_ownership(p
));
18 assert(!__sanitizer_get_ownership(&p
));
19 assert(__sanitizer_get_allocated_size(p
) == size
);
20 assert(__sanitizer_get_allocated_size_fast(p
) == size
);
21 assert(__sanitizer_get_allocated_begin(p
) == p
);
22 assert(__sanitizer_get_allocated_begin(p
+ 1) == p
);
23 assert(__sanitizer_get_current_allocated_bytes() >=
24 size
+ allocated_bytes_before
);
25 assert(__sanitizer_get_current_allocated_bytes() <=
26 2 * size
+ allocated_bytes_before
);
27 assert(__sanitizer_get_heap_size() >= size
);
30 // These are not implemented.
31 assert(__sanitizer_get_unmapped_bytes() <= 1);
32 assert(__sanitizer_get_free_bytes() > 0);
34 __sanitizer_purge_allocator();
37 int main(int argc
, char **argv
) {
38 int size
= atoi(argv
[1]);
42 // Check the thread local caches work as well.
43 std::thread
t(Test
, size
);