#ifdef DYNAMIC
#define OBJECT_SIZE_BUILTIN __builtin_dynamic_object_size
#else
#define OBJECT_SIZE_BUILTIN __builtin_object_size
#endif
#define NULL ((void *)0)
int gi;
typedef unsigned long size_t;
void *my_malloc(size_t) __attribute__((alloc_size(1)));
void *my_calloc(size_t, size_t) __attribute__((alloc_size(1, 2)));
void test1(void) {
void *const vp = my_malloc(100);
gi = OBJECT_SIZE_BUILTIN(vp, 0);
gi = OBJECT_SIZE_BUILTIN(vp, 1);
gi = OBJECT_SIZE_BUILTIN(vp, 2);
gi = OBJECT_SIZE_BUILTIN(vp, 3);
void *const arr = my_calloc(100, 5);
gi = OBJECT_SIZE_BUILTIN(arr, 0);
gi = OBJECT_SIZE_BUILTIN(arr, 1);
gi = OBJECT_SIZE_BUILTIN(arr, 2);
gi = OBJECT_SIZE_BUILTIN(arr, 3);
gi = OBJECT_SIZE_BUILTIN(my_malloc(100), 0);
gi = OBJECT_SIZE_BUILTIN(my_malloc(100), 1);
gi = OBJECT_SIZE_BUILTIN(my_malloc(100), 2);
gi = OBJECT_SIZE_BUILTIN(my_malloc(100), 3);
gi = OBJECT_SIZE_BUILTIN(my_calloc(100, 5), 0);
gi = OBJECT_SIZE_BUILTIN(my_calloc(100, 5), 1);
gi = OBJECT_SIZE_BUILTIN(my_calloc(100, 5), 2);
gi = OBJECT_SIZE_BUILTIN(my_calloc(100, 5), 3);
void *const zeroPtr = my_malloc(0);
gi = OBJECT_SIZE_BUILTIN(zeroPtr, 0);
gi = OBJECT_SIZE_BUILTIN(my_malloc(0), 0);
void *const zeroArr1 = my_calloc(0, 1);
void *const zeroArr2 = my_calloc(1, 0);
gi = OBJECT_SIZE_BUILTIN(zeroArr1, 0);
gi = OBJECT_SIZE_BUILTIN(zeroArr2, 0);
gi = OBJECT_SIZE_BUILTIN(my_calloc(1, 0), 0);
gi = OBJECT_SIZE_BUILTIN(my_calloc(0, 1), 0);
}
void test2(void) {
void *const vp = my_malloc(gi);
gi = OBJECT_SIZE_BUILTIN(vp, 0);
void *const arr1 = my_calloc(gi, 1);
gi = OBJECT_SIZE_BUILTIN(arr1, 0);
void *const arr2 = my_calloc(1, gi);
gi = OBJECT_SIZE_BUILTIN(arr2, 0);
}
void test3(void) {
char *const buf = (char *)my_calloc(100, 5);
gi = OBJECT_SIZE_BUILTIN(buf, 0);
gi = OBJECT_SIZE_BUILTIN(buf, 1);
gi = OBJECT_SIZE_BUILTIN(buf, 2);
gi = OBJECT_SIZE_BUILTIN(buf, 3);
}
struct Data {
int a;
int t[10];
char pad[3];
char end[1];
};
void test5(void) {
struct Data *const data = my_malloc(sizeof(*data));
gi = OBJECT_SIZE_BUILTIN(data, 0);
gi = OBJECT_SIZE_BUILTIN(data, 1);
gi = OBJECT_SIZE_BUILTIN(data, 2);
gi = OBJECT_SIZE_BUILTIN(data, 3);
gi = OBJECT_SIZE_BUILTIN(&data->t[1], 0);
gi = OBJECT_SIZE_BUILTIN(&data->t[1], 1);
gi = OBJECT_SIZE_BUILTIN(&data->t[1], 2);
gi = OBJECT_SIZE_BUILTIN(&data->t[1], 3);
struct Data *const arr = my_calloc(sizeof(*data), 2);
gi = OBJECT_SIZE_BUILTIN(arr, 0);
gi = OBJECT_SIZE_BUILTIN(arr, 1);
gi = OBJECT_SIZE_BUILTIN(arr, 2);
gi = OBJECT_SIZE_BUILTIN(arr, 3);
gi = OBJECT_SIZE_BUILTIN(&arr->t[1], 0);
gi = OBJECT_SIZE_BUILTIN(&arr->t[1], 1);
gi = OBJECT_SIZE_BUILTIN(&arr->t[1], 2);
gi = OBJECT_SIZE_BUILTIN(&arr->t[1], 3);
}
void test6(void) {
struct Data *const data = my_malloc(sizeof(*data) + 10);
gi = OBJECT_SIZE_BUILTIN(data->end, 0);
gi = OBJECT_SIZE_BUILTIN(data->end, 1);
gi = OBJECT_SIZE_BUILTIN(data->end, 2);
gi = OBJECT_SIZE_BUILTIN(data->end, 3);
struct Data *const arr = my_calloc(sizeof(*arr) + 5, 3);
gi = OBJECT_SIZE_BUILTIN(arr->end, 0);
gi = OBJECT_SIZE_BUILTIN(arr->end, 1);
gi = OBJECT_SIZE_BUILTIN(arr->end, 2);
gi = OBJECT_SIZE_BUILTIN(arr->end, 3);
gi = OBJECT_SIZE_BUILTIN(arr[0].end, 0);
gi = OBJECT_SIZE_BUILTIN(arr[0].end, 1);
gi = OBJECT_SIZE_BUILTIN(arr[0].end, 2);
gi = OBJECT_SIZE_BUILTIN(arr[0].end, 3);
gi = OBJECT_SIZE_BUILTIN(arr[1].end, 0);
gi = OBJECT_SIZE_BUILTIN(arr[1].end, 1);
gi = OBJECT_SIZE_BUILTIN(arr[1].end, 2);
gi = OBJECT_SIZE_BUILTIN(arr[1].end, 3);
gi = OBJECT_SIZE_BUILTIN(arr[2].end, 0);
gi = OBJECT_SIZE_BUILTIN(arr[2].end, 1);
gi = OBJECT_SIZE_BUILTIN(arr[2].end, 2);
gi = OBJECT_SIZE_BUILTIN(arr[2].end, 3);
}
void test7(void) {
struct Data *const data = my_malloc(sizeof(*data) + 5);
gi = OBJECT_SIZE_BUILTIN(data->pad, 0);
gi = OBJECT_SIZE_BUILTIN(data->pad, 1);
gi = OBJECT_SIZE_BUILTIN(data->pad, 2);
gi = OBJECT_SIZE_BUILTIN(data->pad, 3);
}
void test8(void) {
void *buf = my_calloc(100, 5);
gi = OBJECT_SIZE_BUILTIN(buf, 0);
gi = OBJECT_SIZE_BUILTIN(buf, 1);
gi = OBJECT_SIZE_BUILTIN(buf, 2);
gi = OBJECT_SIZE_BUILTIN(buf, 3);
}
void test9(void) {
short *const buf0 = (my_malloc(100));
short *const buf1 = (short*)(my_malloc(100));
short *const buf2 = ((short*)(my_malloc(100)));
gi = OBJECT_SIZE_BUILTIN(buf0, 0);
gi = OBJECT_SIZE_BUILTIN(buf1, 0);
gi = OBJECT_SIZE_BUILTIN(buf2, 0);
}
void test10(void) {
short *const arr = my_calloc((size_t)-1 / 2 + 1, 2);
gi = OBJECT_SIZE_BUILTIN(arr, 0);
gi = OBJECT_SIZE_BUILTIN(arr, 1);
gi = OBJECT_SIZE_BUILTIN(arr, 2);
gi = OBJECT_SIZE_BUILTIN(arr, 3);
short *const buf = my_malloc((size_t)-1);
gi = OBJECT_SIZE_BUILTIN(buf, 0);
gi = OBJECT_SIZE_BUILTIN(buf, 1);
gi = OBJECT_SIZE_BUILTIN(buf, 2);
gi = OBJECT_SIZE_BUILTIN(buf, 3);
short *const arr_big = my_calloc((size_t)-1 / 2 - 1, 2);
gi = OBJECT_SIZE_BUILTIN(arr_big, 0);
gi = OBJECT_SIZE_BUILTIN(arr_big, 1);
gi = OBJECT_SIZE_BUILTIN(arr_big, 2);
gi = OBJECT_SIZE_BUILTIN(arr_big, 3);
}
void *my_tiny_malloc(char) __attribute__((alloc_size(1)));
void *my_tiny_calloc(char, char) __attribute__((alloc_size(1, 2)));
void test11(void) {
void *const vp = my_tiny_malloc(100);
gi = OBJECT_SIZE_BUILTIN(vp, 0);
gi = OBJECT_SIZE_BUILTIN(vp, 1);
gi = OBJECT_SIZE_BUILTIN(vp, 2);
gi = OBJECT_SIZE_BUILTIN(vp, 3);
void *const arr = my_tiny_calloc(100, 5);
gi = OBJECT_SIZE_BUILTIN(arr, 0);
gi = OBJECT_SIZE_BUILTIN(arr, 1);
gi = OBJECT_SIZE_BUILTIN(arr, 2);
gi = OBJECT_SIZE_BUILTIN(arr, 3);
}
void *my_signed_malloc(long) __attribute__((alloc_size(1)));
void *my_signed_calloc(long, long) __attribute__((alloc_size(1, 2)));
void test12(void) {
gi = OBJECT_SIZE_BUILTIN(my_signed_malloc(100), 0);
gi = OBJECT_SIZE_BUILTIN(my_signed_calloc(100, 5), 0);
void *const vp = my_signed_malloc(-2);
gi = OBJECT_SIZE_BUILTIN(vp, 0);
gi = OBJECT_SIZE_BUILTIN(my_signed_malloc(-2), 0);
void *const arr1 = my_signed_calloc(-2, 1);
void *const arr2 = my_signed_calloc(1, -2);
gi = OBJECT_SIZE_BUILTIN(arr1, 0);
gi = OBJECT_SIZE_BUILTIN(arr2, 0);
gi = OBJECT_SIZE_BUILTIN(my_signed_calloc(1, -2), 0);
gi = OBJECT_SIZE_BUILTIN(my_signed_calloc(-2, 1), 0);
}
void *alloc_uchar(unsigned char) __attribute__((alloc_size(1)));
void test13(void) {
gi = OBJECT_SIZE_BUILTIN(alloc_uchar(128), 0);
}
void *(*malloc_function_pointer)(int)__attribute__((alloc_size(1)));
void *(*calloc_function_pointer)(int, int)__attribute__((alloc_size(1, 2)));
void test_fn_pointer(void) {
void *const vp = malloc_function_pointer(100);
gi = __builtin_object_size(vp, 0);
gi = __builtin_object_size(vp, 1);
gi = __builtin_object_size(vp, 2);
gi = __builtin_object_size(vp, 3);
void *const arr = calloc_function_pointer(100, 5);
gi = __builtin_object_size(arr, 0);
gi = __builtin_object_size(arr, 1);
gi = __builtin_object_size(arr, 2);
gi = __builtin_object_size(arr, 3);
gi = __builtin_object_size(malloc_function_pointer(100), 0);
gi = __builtin_object_size(malloc_function_pointer(100), 1);
gi = __builtin_object_size(malloc_function_pointer(100), 2);
gi = __builtin_object_size(malloc_function_pointer(100), 3);
gi = __builtin_object_size(calloc_function_pointer(100, 5), 0);
gi = __builtin_object_size(calloc_function_pointer(100, 5), 1);
gi = __builtin_object_size(calloc_function_pointer(100, 5), 2);
gi = __builtin_object_size(calloc_function_pointer(100, 5), 3);
void *const zeroPtr = malloc_function_pointer(0);
gi = __builtin_object_size(zeroPtr, 0);
gi = __builtin_object_size(malloc_function_pointer(0), 0);
void *const zeroArr1 = calloc_function_pointer(0, 1);
void *const zeroArr2 = calloc_function_pointer(1, 0);
gi = __builtin_object_size(zeroArr1, 0);
gi = __builtin_object_size(zeroArr2, 0);
gi = __builtin_object_size(calloc_function_pointer(1, 0), 0);
gi = __builtin_object_size(calloc_function_pointer(0, 1), 0);
}
typedef void *(__attribute__((warn_unused_result, alloc_size(1))) * my_malloc_function_pointer_type)(int);
typedef void *(__attribute__((alloc_size(1, 2))) * my_calloc_function_pointer_type)(int, int);
extern my_malloc_function_pointer_type malloc_function_pointer_with_typedef;
extern my_calloc_function_pointer_type calloc_function_pointer_with_typedef;
void test_fn_pointer_typedef(void) {
malloc_function_pointer_with_typedef(100);
void *const vp = malloc_function_pointer_with_typedef(100);
gi = __builtin_object_size(vp, 0);
gi = __builtin_object_size(vp, 1);
gi = __builtin_object_size(vp, 2);
gi = __builtin_object_size(vp, 3);
void *const arr = calloc_function_pointer_with_typedef(100, 5);
gi = __builtin_object_size(arr, 0);
gi = __builtin_object_size(arr, 1);
gi = __builtin_object_size(arr, 2);
gi = __builtin_object_size(arr, 3);
gi = __builtin_object_size(malloc_function_pointer_with_typedef(100), 0);
gi = __builtin_object_size(malloc_function_pointer_with_typedef(100), 1);
gi = __builtin_object_size(malloc_function_pointer_with_typedef(100), 2);
gi = __builtin_object_size(malloc_function_pointer_with_typedef(100), 3);
gi = __builtin_object_size(calloc_function_pointer_with_typedef(100, 5), 0);
gi = __builtin_object_size(calloc_function_pointer_with_typedef(100, 5), 1);
gi = __builtin_object_size(calloc_function_pointer_with_typedef(100, 5), 2);
gi = __builtin_object_size(calloc_function_pointer_with_typedef(100, 5), 3);
void *const zeroPtr = malloc_function_pointer_with_typedef(0);
gi = __builtin_object_size(zeroPtr, 0);
gi = __builtin_object_size(malloc_function_pointer_with_typedef(0), 0);
void *const zeroArr1 = calloc_function_pointer_with_typedef(0, 1);
void *const zeroArr2 = calloc_function_pointer_with_typedef(1, 0);
gi = __builtin_object_size(zeroArr1, 0);
gi = __builtin_object_size(zeroArr2, 0);
gi = __builtin_object_size(calloc_function_pointer_with_typedef(1, 0), 0);
gi = __builtin_object_size(calloc_function_pointer_with_typedef(0, 1), 0);
}