1 /* PR gcov-profile/97461 */
2 /* { dg-options "-O2 -ldl -fprofile-correction" } */
10 static int malloc_depth
= 0;
12 static char memory
[128* 1024];
13 static size_t memory_p
= 0;
18 typedef void (*fun_t
)(void);
19 static const fun_t funs
[2] = { f1
, f2
, };
21 static void * malloc_impl(size_t size
) {
22 void * r
= &memory
[memory_p
];
23 /* The malloc() and calloc() functions return a pointer to the allocated
24 * memory, which is suitably aligned for any built-in type. Use 16
25 * bytes here as the basic alignment requirement for user-defined malloc
26 * and calloc. See PR97594 for the details. */
27 #define ROUND_UP_FOR_16B_ALIGNMENT(x) ((x + 15) & (-16))
29 memory_p
+= ROUND_UP_FOR_16B_ALIGNMENT(size
);
36 // Override default malloc, check it it get s called recursively
37 void * malloc(size_t size
) {
38 // Must not be called recursively. Malloc implementation does not support it.
39 if (malloc_depth
!= 0) __builtin_trap();
42 void * r
= malloc_impl(size
);
48 void *calloc(size_t nmemb
, size_t size
) {
49 // Must not be called recursively. Malloc implementation does not support it.
50 if (malloc_depth
!= 0) __builtin_trap();
53 void * r
= malloc_impl(size
* nmemb
);
54 memset(r
, 0, size
* nmemb
);
59 void free(void *ptr
){}
63 return p
!= 0 ? 0 : 1;