Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / fuzzer / CallerCalleeTest.cpp
blob4b38983f75319bd57fa76cc5490487792d381535
1 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
2 // See https://llvm.org/LICENSE.txt for license information.
3 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5 // Simple test for a fuzzer.
6 // Try to find the target using the indirect caller-callee pairs.
7 #include <cstddef>
8 #include <cstdint>
9 #include <cstdlib>
10 #include <cstring>
11 #include <iostream>
13 typedef void (*F)();
14 static F t[256];
16 void f34() {
17 std::cerr << "BINGO\n";
18 exit(1);
20 void f23() { t[(unsigned)'d'] = f34;}
21 void f12() { t[(unsigned)'c'] = f23;}
22 void f01() { t[(unsigned)'b'] = f12;}
23 void f00() {}
25 static F t0[256] = {
26 f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00,
27 f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00,
28 f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00,
29 f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00,
30 f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00,
31 f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00,
32 f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00,
33 f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00,
34 f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00,
35 f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00,
36 f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00,
37 f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00,
38 f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00,
39 f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00,
40 f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00,
41 f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00, f00,
44 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
45 if (Size < 4) return 0;
46 // Spoof the counters.
47 for (int i = 0; i < 200; i++) {
48 f23();
49 f12();
50 f01();
52 memcpy(t, t0, sizeof(t));
53 t[(unsigned)'a'] = f01;
54 t[Data[0]]();
55 t[Data[1]]();
56 t[Data[2]]();
57 t[Data[3]]();
58 return 0;