1 //===-- fuzzer_initialize.cpp - Fuzz Clang --------------------------------===//
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
7 //===----------------------------------------------------------------------===//
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.
14 //===----------------------------------------------------------------------===//
16 #include "fuzzer_initialize.h"
18 #include "llvm/InitializePasses.h"
19 #include "llvm/PassRegistry.h"
20 #include "llvm/Support/TargetSelect.h"
23 using namespace clang_fuzzer
;
27 namespace clang_fuzzer
{
29 static std::vector
<const char *> CLArgs
;
31 const std::vector
<const char *>& GetCLArgs() {
37 extern "C" int LLVMFuzzerInitialize(int *argc
, char ***argv
) {
38 InitializeAllTargets();
39 InitializeAllTargetMCs();
40 InitializeAllAsmPrinters();
41 InitializeAllAsmParsers();
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
);
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
]);