1#include <stdio.h>
2#include <stdlib.h>
3#include <vector>
4
5using namespace std;
6
7class Base {
8public:
9 virtual int Foo() = 0;
10};
11
12class Derived1 : public Base {
13public:
14 int Foo() override { return 1; }
15};
16
17class Derived2 : public Base {
18public:
19 int Foo() override { return 2; }
20};
21
22class Derived3 : public Base {
23public:
24 int Foo() override { return 3; }
25};
26
27int main(int argc, char *argv[]) {
28 long long sum = 0;
29 int outerIters = atoi(nptr: argv[1]);
30 int selector = atoi(nptr: argv[2]);
31
32 Base *obj1 = new Derived1();
33 Base *obj2 = new Derived2();
34 Base *obj3 = new Derived3();
35
36 for (int j = 0; j < outerIters; j++) {
37 for (int i = 0; i < 10000; i++) {
38 switch (selector) {
39 case 1: sum += obj1->Foo(); break;
40 case 2: sum += obj2->Foo(); break;
41 case 3: sum += obj3->Foo(); break;
42 }
43 }
44 }
45 printf(format: "%lld\n", sum);
46}
47

source code of bolt/test/runtime/X86/Inputs/retpoline_synthetic.cpp