• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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>
foo()5 __attribute__((noinline)) void foo() {}
foo2()6 __attribute__((noinline)) void foo2() {}
7 void (*FP)();
8 int MainEntered = 0;
9 int CallocCalled = 0;
10 int MallocCalled = 0;
11 
12 extern void *__real_calloc(size_t s, size_t n);
13 extern void *__real_malloc(size_t s);
14 
__wrap_calloc(size_t s,size_t n)15 void *__wrap_calloc(size_t s, size_t n) {
16   if (MainEntered)
17     CallocCalled = 1;
18   return __real_calloc(s, n);
19 }
__wrap_malloc(size_t s)20 void *__wrap_malloc(size_t s) {
21   if (MainEntered)
22     MallocCalled = 1;
23   return __real_malloc(s);
24 }
25 
getFP(int i)26 void getFP(int i) {
27   if (i % 2)
28     FP = foo;
29   else
30     FP = foo2;
31 }
32 
main()33 int 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