blob: 2b9de88d7308d3e28f49c9c56a04b65238acf1e3 [file] [log] [blame]
Max Moroz08dad542018-07-16 16:01:31 +00001#include <assert.h>
2#include <cstdint>
3#include <cstdio>
4#include <cstdlib>
5
6int x = 0;
7bool skip0 = false;
8bool skip1 = false;
9bool skip2 = false;
10
11__attribute__((noinline)) void det0() { x++; }
12__attribute__((noinline)) void det1() { x++; }
13__attribute__((noinline)) void det2() { x++; }
14__attribute__((noinline)) void det3() { x++; }
15__attribute__((noinline)) void det4() { x++; }
16
17__attribute__((noinline)) void ini0() { x++; }
18__attribute__((noinline)) void ini1() { x++; }
19__attribute__((noinline)) void ini2() { x++; }
20
Max Moroz84a48272018-08-06 23:14:13 +000021__attribute__((noinline)) void t0(int a) { x += a; }
Max Moroz08dad542018-07-16 16:01:31 +000022__attribute__((noinline)) void t1() { x++; }
Max Moroz84a48272018-08-06 23:14:13 +000023__attribute__((noinline)) void t2(int a, int b) { x += a + b; }
Max Moroz08dad542018-07-16 16:01:31 +000024__attribute__((noinline)) void t3() { x++; }
Max Moroz84a48272018-08-06 23:14:13 +000025__attribute__((noinline)) void t4(int a, int b, int c) { x += a + b +c; }
Max Moroz08dad542018-07-16 16:01:31 +000026
27extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
28 if (Size == 1 && Data[0] == 'A' && !skip0) {
29 skip0 = true;
30 ini0();
31 }
32 if (Size == 1 && Data[0] == 'B' && !skip1) {
33 skip1 = true;
34 ini1();
35 }
36 if (Size == 1 && Data[0] == 'C' && !skip2) {
37 skip2 = true;
38 ini2();
39 }
40
41 det0();
42 det1();
43 int a = rand();
44 det2();
45
46 switch (a % 5) {
47 case 0:
Max Moroz84a48272018-08-06 23:14:13 +000048 t0(a);
Max Moroz08dad542018-07-16 16:01:31 +000049 break;
50 case 1:
51 t1();
52 break;
53 case 2:
Max Moroz84a48272018-08-06 23:14:13 +000054 t2(a, a);
Max Moroz08dad542018-07-16 16:01:31 +000055 break;
56 case 3:
57 t3();
58 break;
59 case 4:
Max Moroz84a48272018-08-06 23:14:13 +000060 t4(a, a, a);
Max Moroz08dad542018-07-16 16:01:31 +000061 break;
62 default:
63 assert(false);
64 }
65
66 det3();
67 det4();
68 return 0;
69}