1/* This test case tests that when static allocation for value
2 * profiler is on, no malloc/calloc calls will be invoked by
3 * profile runtime library. */
4#include <stdlib.h>
5__attribute__((noinline)) void foo() {}
6__attribute__((noinline)) void foo2() {}
7void (*FP)();
8int MainEntered = 0;
9int CallocCalled = 0;
10int MallocCalled = 0;
11
12extern void *__real_calloc(size_t s, size_t n);
13extern void *__real_malloc(size_t s);
14
15void *__wrap_calloc(size_t s, size_t n) {
16 if (MainEntered)
17 CallocCalled = 1;
18 return __real_calloc(s, n);
19}
20void *__wrap_malloc(size_t s) {
21 if (MainEntered)
22 MallocCalled = 1;
23 return __real_malloc(s);
24}
25
26void getFP(int i) {
27 if (i % 2)
28 FP = foo;
29 else
30 FP = foo2;
31}
32
33int main() {
34 int i;
35 MainEntered = 1;
36 for (i = 0; i < 100; i++) {
37 getFP(i);
38 FP();
39 }
40 return CallocCalled + MallocCalled;
41}
42

source code of compiler-rt/test/profile/Inputs/instrprof-alloc.c