1 // RUN: %clangxx -O0 -g %s -o %t && %run %t
3 // Must not be implemented, no other reason to install interceptors.
7 #include <sanitizer/allocator_interface.h>
12 // Based on lib/msan/tests/msan_test.cpp::get_allocated_size_and_ownership
14 int sizes
[] = {10, 100, 1000, 10000, 100000, 1000000};
16 for (int i
= 0; i
< sizeof(sizes
) / sizeof(int); i
++) {
17 printf("Testing size %d\n", sizes
[i
]);
19 char *array
= reinterpret_cast<char *>(malloc(sizes
[i
]));
20 int *int_ptr
= new int;
21 printf("array: %p\n", array
);
22 printf("int_ptr: %p\n", int_ptr
);
24 // Bogus value to unpoison start. Calling __sanitizer_get_allocated_begin
25 // does not unpoison it.
26 const void *start
= NULL
;
27 for (int j
= 0; j
< sizes
[i
]; j
++) {
29 start
= __sanitizer_get_allocated_begin(array
+ j
);
32 printf("Start: %p (expected: %p)\n", start
, array
);
35 assert(array
== start
);
38 start
= __sanitizer_get_allocated_begin(int_ptr
);
39 assert(int_ptr
== start
);
41 void *wild_addr
= reinterpret_cast<void *>(4096 * 160);
42 assert(__sanitizer_get_allocated_begin(wild_addr
) == NULL
);
44 wild_addr
= reinterpret_cast<void *>(0x1);
45 assert(__sanitizer_get_allocated_begin(wild_addr
) == NULL
);
47 // NULL is a valid argument for GetAllocatedSize but is not owned.
48 assert(__sanitizer_get_allocated_begin(NULL
) == NULL
);
51 for (int j
= 0; j
< sizes
[i
]; j
++) {
52 assert(__sanitizer_get_allocated_begin(array
+ j
) == NULL
);
56 assert(__sanitizer_get_allocated_begin(int_ptr
) == NULL
);