Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / fuzzer / RepeatedBytesTest.cpp
blob1ed822a3de5ffbced38a80622c9b0013b71f4758
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. The fuzzer must find repeated bytes.
6 #include <assert.h>
7 #include <cstddef>
8 #include <cstdint>
9 #include <cstdlib>
10 #include <iostream>
11 #include <ostream>
13 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
14 assert(Data);
15 // Looking for AAAAAAAAAAAAAAAAAAAAAA or some such.
16 size_t CurA = 0, MaxA = 0;
17 for (size_t i = 0; i < Size; i++) {
18 // Make sure there are no conditionals in the loop so that
19 // coverage can't help the fuzzer.
20 int EQ = Data[i] == 'A';
21 CurA = EQ * (CurA + 1);
22 int GT = CurA > MaxA;
23 MaxA = GT * CurA + (!GT) * MaxA;
25 if (MaxA >= 20) {
26 std::cout << "BINGO; Found the target (Max: " << MaxA << "), exiting\n"
27 << std::flush;
28 exit(0);
30 return 0;