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
4
5// Find "FUZZME", the target has 3 different functions.
6//
7// This test, and the accompanying lit tests
8// (dataflow.test, only-some-bytes.test) assume that the compiler
9// instruments functions in their lexical order.
10// This assumption is not guaranteed, but it is likely to hold.
11// It allows to simplify the test quite a bit: in the lit tests
12// LLVMFuzzerTestOneInput is "F0", Func1 is "F1", Func2 is "F2".
13#include <assert.h>
14#include <cstddef>
15#include <cstdint>
16#include <cstdlib>
17#include <cstdio>
18
19extern "C" bool Func1(const uint8_t *Data, size_t Size);
20extern "C" bool Func2(const uint8_t *Data, size_t Size);
21
22extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
23 if (Size >= 5
24 && Data[0] == 'F'
25 && Data[1] == 'U'
26 && Data[2] == 'Z'
27 && Data[3] == 'Z'
28 && Func1(Data, Size)
29 && Func2(Data, Size)) {
30 fprintf(stderr, format: "BINGO\n");
31 abort();
32 }
33 return 0;
34}
35
36extern "C"
37__attribute__((noinline))
38bool Func1(const uint8_t *Data, size_t Size) {
39 // assumes Size >= 5, doesn't check it.
40 return Data[4] == 'M';
41}
42
43extern "C"
44__attribute__((noinline))
45bool Func2(const uint8_t *Data, size_t Size) {
46 return Size >= 6 && Data[5] == 'E';
47}
48
49
50

source code of compiler-rt/test/fuzzer/ThreeFunctionsTest.cpp