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-exception
6//
7//===----------------------------------------------------------------------===//
8///
9/// \file
10/// This file implements two functions: one that returns the command line
11/// arguments for a given call to the fuzz target and one that initializes
12/// 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(x: "-O2");
54 for (int I = 1; I < *argc; I++) {
55 if (strcmp(s1: (*argv)[I], s2: "-ignore_remaining_args=1") == 0) {
56 for (I++; I < *argc; I++)
57 CLArgs.push_back(x: (*argv)[I]);
58 break;
59 }
60 }
61 return 0;
62}
63

source code of clang/tools/clang-fuzzer/fuzzer-initialize/fuzzer_initialize.cpp