Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / fuzzer / MsanCustomMutator.cpp
blob5c783e9c31d4f1264f68785f0125b3a5cf5ebec8
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 // Triggers the bug described here:
6 // https://github.com/google/oss-fuzz/issues/4605
7 //
8 // Tests that custom mutators do not cause MSan false positives. We are careful
9 // to use every parameter to ensure none cause false positives.
11 #include <algorithm>
12 #include <cstddef>
13 #include <cstdint>
14 #include <cstdio>
15 #include <cstring>
17 extern "C" {
19 int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { return 0; }
21 size_t LLVMFuzzerCustomMutator(uint8_t *Data, size_t Size, size_t MaxSize,
22 unsigned int Seed) {
23 if (Seed == 7)
24 return 0;
25 if (MaxSize == 0)
26 return 0;
27 for (size_t I = 0; I < Size; ++I) {
28 if (Data[I] == 42) {
29 printf("BINGO\n");
32 return Size;
35 size_t LLVMFuzzerCustomCrossOver(
36 const uint8_t *Data1, size_t Size1, const uint8_t *Data2, size_t Size2,
37 uint8_t *Out, size_t MaxOutSize, unsigned int Seed) {
38 if (Seed == 7)
39 return 0;
40 size_t I = 0;
41 for (; I < Size1 && I < Size2 && I < MaxOutSize; ++I) {
42 Out[I] = std::min(Data1[I], Data2[I]);
44 return I;
47 } // extern "C"