CCTLib
Calling-context and data-object attribution library for Intel Pin
rec_fib_deep.cpp
Go to the documentation of this file.
1 // Canonical direct self-recursion: naive Fibonacci. fib() contains two
2 // direct calls to itself; the classifier must see both, populate
3 // selfRecReturnAddrs with the return address after each call, and fold
4 // every recursive activation into a single TraceNode. fib(15) exercises
5 // depth 16 (comfortably under cctlib's MAX_CCT_PRINT_DEPTH=20 so the
6 // sensitivity of the shape assertion isn't blunted by chain truncation
7 // when the collapse mechanism is intentionally disabled).
8 #include <cstdint>
9 #include <cstdio>
10 
11 static volatile int64_t sink;
12 
13 static int64_t fib(int n) {
14  if (n < 2) return n;
15  return fib(n - 1) + fib(n - 2);
16 }
17 
18 int main(int argc, char** argv) {
19  (void)argc; (void)argv;
20  int64_t r = fib(15);
21  sink ^= r;
22  fprintf(stderr, "rec_fib_deep: fib(15)=%lld sink=%llx\n",
23  (long long)r, (unsigned long long)sink);
24  return r == 610 ? 0 : 1;
25 }
static int64_t fib(int n)
int main(int argc, char **argv)
static volatile int64_t sink