1#include <stdio.h>
2
3typedef int (*func_ptr)(int, int);
4
5int add(int a, int b) { return a + b; }
6
7int main() {
8 func_ptr fun;
9 fun = add;
10 int sum = fun(10, 20); // indirect call to 'add'
11 printf(format: "The sum is: %d\n", sum);
12 return 0;
13}
14/*
15REQUIRES: system-linux,bolt-runtime
16
17RUN: %clang %cflags %s -o %t.exe -Wl,-q -no-pie -fpie
18
19RUN: llvm-bolt %t.exe --instrument --instrumentation-file=%t.fdata \
20RUN: -o %t.instrumented
21
22# Instrumented program needs to finish returning zero
23RUN: %t.instrumented | FileCheck %s -check-prefix=CHECK-OUTPUT
24
25# Test that the instrumented data makes sense
26RUN: llvm-bolt %t.exe -o %t.bolted --data %t.fdata \
27RUN: --reorder-blocks=ext-tsp --reorder-functions=hfsort+ \
28RUN: --print-only=main --print-finalized | FileCheck %s
29
30RUN: %t.bolted | FileCheck %s -check-prefix=CHECK-OUTPUT
31
32CHECK-OUTPUT: The sum is: 30
33
34# Check that our indirect call has 1 hit recorded in the fdata file and that
35# this was processed correctly by BOLT
36CHECK: blr x8 # CallProfile: 1 (0 misses) :
37CHECK-NEXT: { add: 1 (0 misses) }
38*/
39

source code of bolt/test/runtime/AArch64/instrumentation-ind-call.c