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// Source code for a simple DSO.
6
7#include <cstdint>
8#include <cstdio>
9#include <cstdlib>
10#include <cstring>
11extern int DSO1(int a);
12extern int DSO2(int a);
13extern int DSOTestExtra(int a);
14
15static volatile int *nil = 0;
16
17extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
18 int x, y, z;
19 if (Size < sizeof(int) * 3) {
20 x = y = z = 0;
21 } else {
22 memcpy(dest: &x, src: Data + 0 * sizeof(int), n: sizeof(int));
23 memcpy(dest: &y, src: Data + 1 * sizeof(int), n: sizeof(int));
24 memcpy(dest: &z, src: Data + 2 * sizeof(int), n: sizeof(int));
25 }
26 int sum = DSO1(a: x) + DSO2(a: y) + (z ? DSOTestExtra(a: z) : 0);
27 if (sum == 3) {
28 fprintf(stderr, format: "BINGO %d %d %d\n", x, y, z);
29 *nil = 0;
30 }
31 return 0;
32}
33

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