19 std::vector<const char *> CLArgs;
20 CLArgs.push_back(ArgV[0]);
24 if (
StringRef(ArgV[
I++]).equals(
"-ignore_remaining_args=1"))
27 CLArgs.push_back(ArgV[
I++]);
33 std::vector<std::string> Args{std::string(ExecName)};
35 auto NameAndArgs = ExecName.
split(
"--");
36 if (NameAndArgs.second.empty())
40 NameAndArgs.second.split(Opts,
'-');
42 if (Opt.equals(
"gisel")) {
43 Args.push_back(
"-global-isel");
45 Args.push_back(
"-O0");
46 }
else if (Opt.startswith(
"O")) {
47 Args.push_back(
"-" + Opt.str());
48 }
else if (
Triple(Opt).getArch()) {
49 Args.push_back(
"-mtriple=" + Opt.str());
51 errs() << ExecName <<
": Unknown option: " << Opt <<
".\n";
55 errs() << NameAndArgs.first <<
": Injected args:";
56 for (
int I = 1,
E = Args.size();
I <
E; ++
I)
57 errs() <<
" " << Args[
I];
60 std::vector<const char *> CLArgs;
61 CLArgs.reserve(Args.size());
62 for (std::string &S : Args)
63 CLArgs.push_back(S.c_str());
70 std::vector<std::string> Args{std::string(ExecName)};
72 auto NameAndArgs = ExecName.
split(
"--");
73 if (NameAndArgs.second.empty())
77 NameAndArgs.second.split(Opts,
'-');
79 if (Opt ==
"instcombine") {
80 Args.push_back(
"-passes=instcombine");
81 }
else if (Opt ==
"earlycse") {
82 Args.push_back(
"-passes=early-cse");
83 }
else if (Opt ==
"simplifycfg") {
84 Args.push_back(
"-passes=simplifycfg");
85 }
else if (Opt ==
"gvn") {
86 Args.push_back(
"-passes=gvn");
87 }
else if (Opt ==
"sccp") {
88 Args.push_back(
"-passes=sccp");
90 }
else if (Opt ==
"loop_predication") {
91 Args.push_back(
"-passes=loop-predication");
92 }
else if (Opt ==
"guard_widening") {
93 Args.push_back(
"-passes=guard-widening");
94 }
else if (Opt ==
"loop_rotate") {
95 Args.push_back(
"-passes=loop(rotate)");
96 }
else if (Opt ==
"loop_unswitch") {
97 Args.push_back(
"-passes=loop(simple-loop-unswitch)");
98 }
else if (Opt ==
"loop_unroll") {
99 Args.push_back(
"-passes=unroll");
100 }
else if (Opt ==
"loop_vectorize") {
101 Args.push_back(
"-passes=loop-vectorize");
102 }
else if (Opt ==
"licm") {
103 Args.push_back(
"-passes=licm");
104 }
else if (Opt ==
"indvars") {
105 Args.push_back(
"-passes=indvars");
106 }
else if (Opt ==
"strength_reduce") {
107 Args.push_back(
"-passes=loop-reduce");
108 }
else if (Opt ==
"irce") {
109 Args.push_back(
"-passes=irce");
111 }
else if (
Triple(Opt).getArch()) {
112 Args.push_back(
"-mtriple=" + Opt.str());
114 errs() << ExecName <<
": Unknown option: " << Opt <<
".\n";
119 errs() << NameAndArgs.first <<
": Injected args:";
120 for (
int I = 1,
E = Args.size();
I <
E; ++
I)
121 errs() <<
" " << Args[
I];
124 std::vector<const char *> CLArgs;
125 CLArgs.reserve(Args.size());
126 for (std::string &S : Args)
127 CLArgs.push_back(S.c_str());
134 errs() <<
"*** This tool was not linked to libFuzzer.\n"
135 <<
"*** No fuzzing will be performed.\n";
136 if (
int RC =
Init(&ArgC, &ArgV)) {
137 errs() <<
"Initialization failed\n";
141 for (
int I = 1;
I < ArgC; ++
I) {
144 if (Arg.
equals(
"-ignore_remaining_args=1"))
151 if (std::error_code EC = BufOrErr.getError()) {
152 errs() <<
"Error reading file: " << Arg <<
": " << EC.message() <<
"\n";
155 std::unique_ptr<MemoryBuffer> Buf = std::move(BufOrErr.get());
156 errs() <<
"Running: " << Arg <<
" (" << Buf->getBufferSize() <<
" bytes)\n";
157 TestOne(
reinterpret_cast<const uint8_t *
>(Buf->getBufferStart()),
158 Buf->getBufferSize());
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static ErrorOr< std::unique_ptr< MemoryBuffer > > getFile(const Twine &Filename, bool IsText=false, bool RequiresNullTerminator=true, bool IsVolatile=false, std::optional< Align > Alignment=std::nullopt)
Open the specified file as a MemoryBuffer, returning a new MemoryBuffer if successful,...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
bool startswith(StringRef Prefix) const
bool equals(StringRef RHS) const
equals - Check for string equality, this is more efficient than compare() when the relative ordering ...
Triple - Helper class for working with autoconf configuration names.
bool ParseCommandLineOptions(int argc, const char *const *argv, StringRef Overview="", raw_ostream *Errs=nullptr, const char *EnvVar=nullptr, bool LongOptionsUseDoubleDash=false)
This is an optimization pass for GlobalISel generic memory operations.
int(*)(int *argc, char ***argv) FuzzerInitFun
int(*)(const uint8_t *Data, size_t Size) FuzzerTestFun
void handleExecNameEncodedBEOpts(StringRef ExecName)
Handle backend options that are encoded in the executable name.
int runFuzzerOnInputs(int ArgC, char *ArgV[], FuzzerTestFun TestOne, FuzzerInitFun Init=[](int *, char ***) { return 0;})
Runs a fuzz target on the inputs specified on the command line.
void handleExecNameEncodedOptimizerOpts(StringRef ExecName)
Handle optimizer options which are encoded in the executable name.
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
void parseFuzzerCLOpts(int ArgC, char *ArgV[])
Parse cl::opts from a fuzz target commandline.