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

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