brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.7 KiB · 94f3b93 Raw
63 lines · cpp
1//===-- fuzzer_initialize.cpp - Fuzz Clang --------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8///9/// \file10/// This file implements two functions: one that returns the command line11/// arguments for a given call to the fuzz target and one that initializes12/// the fuzzer with the correct command line arguments.13///14//===----------------------------------------------------------------------===//15 16#include "fuzzer_initialize.h"17 18#include "llvm/InitializePasses.h"19#include "llvm/PassRegistry.h"20#include "llvm/Support/TargetSelect.h"21#include <cstring>22 23using namespace clang_fuzzer;24using namespace llvm;25 26 27namespace clang_fuzzer {28 29static std::vector<const char *> CLArgs;30 31const std::vector<const char *>& GetCLArgs() {32  return CLArgs;33}34 35}36 37extern "C" int LLVMFuzzerInitialize(int *argc, char ***argv) {38  InitializeAllTargets();39  InitializeAllTargetMCs();40  InitializeAllAsmPrinters();41  InitializeAllAsmParsers();42  43  PassRegistry &Registry = *PassRegistry::getPassRegistry();44  initializeCore(Registry);45  initializeScalarOpts(Registry);46  initializeVectorization(Registry);47  initializeIPO(Registry);48  initializeAnalysis(Registry);49  initializeTransformUtils(Registry);50  initializeInstCombine(Registry);51  initializeTarget(Registry);52 53  CLArgs.push_back("-O2");54  for (int I = 1; I < *argc; I++) {55    if (strcmp((*argv)[I], "-ignore_remaining_args=1") == 0) {56      for (I++; I < *argc; I++)57        CLArgs.push_back((*argv)[I]);58      break;59    }60  }61  return 0;62}63