xref: /openbsd-src/gnu/llvm/clang/tools/clang-fuzzer/ClangFuzzer.cpp (revision e5dd70708596ae51455a0ffa086a00c5b29f8583)
1*e5dd7070Spatrick //===-- ClangFuzzer.cpp - Fuzz Clang --------------------------------------===//
2*e5dd7070Spatrick //
3*e5dd7070Spatrick // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*e5dd7070Spatrick // See https://llvm.org/LICENSE.txt for license information.
5*e5dd7070Spatrick // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*e5dd7070Spatrick //
7*e5dd7070Spatrick //===----------------------------------------------------------------------===//
8*e5dd7070Spatrick ///
9*e5dd7070Spatrick /// \file
10*e5dd7070Spatrick /// This file implements a function that runs Clang on a single
11*e5dd7070Spatrick ///  input. This function is then linked into the Fuzzer library.
12*e5dd7070Spatrick ///
13*e5dd7070Spatrick //===----------------------------------------------------------------------===//
14*e5dd7070Spatrick 
15*e5dd7070Spatrick #include "handle-cxx/handle_cxx.h"
16*e5dd7070Spatrick 
17*e5dd7070Spatrick using namespace clang_fuzzer;
18*e5dd7070Spatrick 
LLVMFuzzerInitialize(int * argc,char *** argv)19*e5dd7070Spatrick extern "C" int LLVMFuzzerInitialize(int *argc, char ***argv) { return 0; }
20*e5dd7070Spatrick 
LLVMFuzzerTestOneInput(uint8_t * data,size_t size)21*e5dd7070Spatrick extern "C" int LLVMFuzzerTestOneInput(uint8_t *data, size_t size) {
22*e5dd7070Spatrick   std::string s((const char *)data, size);
23*e5dd7070Spatrick   HandleCXX(s, "./test.cc", {"-O2"});
24*e5dd7070Spatrick   return 0;
25*e5dd7070Spatrick }
26