1293c2691SMatt Morehouse //===-- fuzzer_initialize.cpp - Fuzz Clang --------------------------------===// 2293c2691SMatt Morehouse // 3*2946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4*2946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information. 5*2946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6293c2691SMatt Morehouse // 7293c2691SMatt Morehouse //===----------------------------------------------------------------------===// 8293c2691SMatt Morehouse /// 9293c2691SMatt Morehouse /// \file 10293c2691SMatt Morehouse /// This file implements two functions: one that returns the command line 11293c2691SMatt Morehouse /// arguments for a given call to the fuzz target and one that initializes 12293c2691SMatt Morehouse /// the fuzzer with the correct command line arguments. 13293c2691SMatt Morehouse /// 14293c2691SMatt Morehouse //===----------------------------------------------------------------------===// 15293c2691SMatt Morehouse 16293c2691SMatt Morehouse #include "fuzzer_initialize.h" 17e5f4a9ffSEmmett Neyman 18e5581242SEmmett Neyman #include "llvm/InitializePasses.h" 19e5581242SEmmett Neyman #include "llvm/PassRegistry.h" 20e5f4a9ffSEmmett Neyman #include "llvm/Support/TargetSelect.h" 21293c2691SMatt Morehouse #include <cstring> 22293c2691SMatt Morehouse 23293c2691SMatt Morehouse using namespace clang_fuzzer; 24e5581242SEmmett Neyman using namespace llvm; 25293c2691SMatt Morehouse 26293c2691SMatt Morehouse 27293c2691SMatt Morehouse namespace clang_fuzzer { 28293c2691SMatt Morehouse 29293c2691SMatt Morehouse static std::vector<const char *> CLArgs; 30293c2691SMatt Morehouse GetCLArgs()31293c2691SMatt Morehouseconst std::vector<const char *>& GetCLArgs() { 32293c2691SMatt Morehouse return CLArgs; 33293c2691SMatt Morehouse } 34293c2691SMatt Morehouse 35293c2691SMatt Morehouse } 36293c2691SMatt Morehouse LLVMFuzzerInitialize(int * argc,char *** argv)37293c2691SMatt Morehouseextern "C" int LLVMFuzzerInitialize(int *argc, char ***argv) { 38e5581242SEmmett Neyman InitializeAllTargets(); 39e5581242SEmmett Neyman InitializeAllTargetMCs(); 40e5581242SEmmett Neyman InitializeAllAsmPrinters(); 41e5581242SEmmett Neyman InitializeAllAsmParsers(); 42e5581242SEmmett Neyman 43e5581242SEmmett Neyman PassRegistry &Registry = *PassRegistry::getPassRegistry(); 44e5581242SEmmett Neyman initializeCore(Registry); 45e5581242SEmmett Neyman initializeScalarOpts(Registry); 46e5581242SEmmett Neyman initializeVectorization(Registry); 47e5581242SEmmett Neyman initializeIPO(Registry); 48e5581242SEmmett Neyman initializeAnalysis(Registry); 49e5581242SEmmett Neyman initializeTransformUtils(Registry); 50e5581242SEmmett Neyman initializeInstCombine(Registry); 51e5581242SEmmett Neyman initializeTarget(Registry); 52e5f4a9ffSEmmett Neyman 53293c2691SMatt Morehouse CLArgs.push_back("-O2"); 54293c2691SMatt Morehouse for (int I = 1; I < *argc; I++) { 55293c2691SMatt Morehouse if (strcmp((*argv)[I], "-ignore_remaining_args=1") == 0) { 56293c2691SMatt Morehouse for (I++; I < *argc; I++) 57293c2691SMatt Morehouse CLArgs.push_back((*argv)[I]); 58293c2691SMatt Morehouse break; 59293c2691SMatt Morehouse } 60293c2691SMatt Morehouse } 61293c2691SMatt Morehouse return 0; 62293c2691SMatt Morehouse } 63