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
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
; }
21 if (n
== 0) return 1; else return mul(n
, fact2(n
-1));
25 if (n
== 0) return 1; else return mul(n
, fact1(n
-1));
29 int I_WRAP_SONAME_FNNAME_ZU(NONE
,fact1
) ( int n
)
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);
41 int I_WRAP_SONAME_FNNAME_ZU(NONE
,fact2
) ( int n
)
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
);
57 printf("computing fact1(5)\n");
59 printf("fact1(5) = %d\n", r
);