CCTLib
Calling-context and data-object attribution library for Intel Pin
rec_multi_direct.cpp
Go to the documentation of this file.
1 // Three static direct self-call sites in three different basic blocks
2 // of the same routine. Each site's INS_NextAddress differs. Verifies
3 // that MaybeGoUpCallChain's per-routine set correctly enumerates all
4 // N return addresses -- a bug that matched only one would corrupt the
5 // CCT on returns from the other two sites.
6 //
7 // Structure: multi(n) picks one of three recursive descents based on
8 // n%3, driving the interpreter through every self-call site over many
9 // iterations. Each site does slightly different arithmetic so the
10 // compiler can't fold them together.
11 #include <cstdint>
12 #include <cstdio>
13 
14 static volatile uint64_t sink;
15 
16 static uint64_t multi(int n) {
17  if (n <= 0) return 1;
18  if ((n % 3) == 0) {
19  uint64_t a = multi(n - 1); // site 1
20  return a + 1;
21  } else if ((n % 3) == 1) {
22  uint64_t b = multi(n - 1); // site 2
23  return b * 2;
24  } else {
25  uint64_t c = multi(n - 1); // site 3
26  return c ^ 3;
27  }
28 }
29 
30 int main(int argc, char** argv) {
31  (void)argc; (void)argv;
32  // depth of 15 -> 15 recursive activations cycling through all 3
33  // sites. Kept under cctlib's MAX_CCT_PRINT_DEPTH=20 so the shape
34  // check remains sensitive when collapse is disabled.
35  uint64_t r = multi(15);
36  sink ^= r;
37  fprintf(stderr, "rec_multi_direct: multi(15)=%llu sink=%llx\n",
38  (unsigned long long)r, (unsigned long long)sink);
39  return 0;
40 }
static uint64_t multi(int n)
int main(int argc, char **argv)
static volatile uint64_t sink
int a[1000]
Definition: testArray.c:5