regtest: dhat/tests/user_histo1 filter out summary
[valgrind.git] / memcheck / tests / wrap4.c
blobbdc6a3b9c981460a4672117543a93aa04a186632
2 #include <stdio.h>
3 #include "valgrind.h"
5 /* Check that it's safe to call a wrapped function from some other
6 function's wrapper. Note that because the wrapper for fact1
7 actually interferes with the computation of the result, this
8 program produces a different answer when run on V (162) from
9 natively (120).
12 static int fact1 ( int n );
13 static int fact2 ( int n );
15 /* This is needed to stop gcc4 turning 'fact' into a loop */
16 __attribute__((noinline))
17 int mul ( int x, int y ) { return x * y; }
19 int fact1 ( int n )
21 if (n == 0) return 1; else return mul(n, fact2(n-1));
23 int fact2 ( int n )
25 if (n == 0) return 1; else return mul(n, fact1(n-1));
29 int I_WRAP_SONAME_FNNAME_ZU(NONE,fact1) ( int n )
31 int r;
32 OrigFn fn;
33 VALGRIND_GET_ORIG_FN(fn);
34 printf("in wrapper1-pre: fact(%d)\n", n);
35 CALL_FN_W_W(r, fn, n);
36 printf("in wrapper1-post: fact(%d) = %d\n", n, r);
37 if (n >= 3) r += fact2(2);
38 return r;
41 int I_WRAP_SONAME_FNNAME_ZU(NONE,fact2) ( int n )
43 int r;
44 OrigFn fn;
45 VALGRIND_GET_ORIG_FN(fn);
46 printf("in wrapper2-pre: fact(%d)\n", n);
47 CALL_FN_W_W(r, fn, n);
48 printf("in wrapper2-post: fact(%d) = %d\n", n, r);
49 return r;
52 /* --------------- */
54 int main ( void )
56 int r;
57 printf("computing fact1(5)\n");
58 r = fact1(5);
59 printf("fact1(5) = %d\n", r);
60 return 0;