19 std::vector<const char *> CLArgs;
20 CLArgs.push_back(ArgV[0]);
24 if (
StringRef(ArgV[
I++]) ==
"-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,
'-');
43 Args.push_back(
"-global-isel");
45 Args.push_back(
"-O0");
46 }
else if (Opt.starts_with(
"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");
89 }
else if (Opt ==
"loop_predication") {
90 Args.push_back(
"-passes=loop-predication");
91 }
else if (Opt ==
"guard_widening") {
92 Args.push_back(
"-passes=guard-widening");
93 }
else if (Opt ==
"loop_rotate") {
94 Args.push_back(
"-passes=loop-rotate");
95 }
else if (Opt ==
"loop_unswitch") {
96 Args.push_back(
"-passes=loop(simple-loop-unswitch)");
97 }
else if (Opt ==
"loop_unroll") {
98 Args.push_back(
"-passes=unroll");
99 }
else if (Opt ==
"loop_vectorize") {
100 Args.push_back(
"-passes=loop-vectorize");
101 }
else if (Opt ==
"licm") {
102 Args.push_back(
"-passes=licm");
103 }
else if (Opt ==
"indvars") {
104 Args.push_back(
"-passes=indvars");
105 }
else if (Opt ==
"strength_reduce") {
106 Args.push_back(
"-passes=loop-reduce");
107 }
else if (Opt ==
"irce") {
108 Args.push_back(
"-passes=irce");
109 }
else if (Opt ==
"dse") {
110 Args.push_back(
"-passes=dse");
111 }
else if (Opt ==
"loop_idiom") {
112 Args.push_back(
"-passes=loop-idiom");
113 }
else if (Opt ==
"reassociate") {
114 Args.push_back(
"-passes=reassociate");
115 }
else if (Opt ==
"lower_matrix_intrinsics") {
116 Args.push_back(
"-passes=lower-matrix-intrinsics");
117 }
else if (Opt ==
"memcpyopt") {
118 Args.push_back(
"-passes=memcpyopt");
119 }
else if (Opt ==
"sroa") {
120 Args.push_back(
"-passes=sroa");
121 }
else if (
Triple(Opt).getArch()) {
122 Args.push_back(
"-mtriple=" + Opt.str());
124 errs() << ExecName <<
": Unknown option: " << Opt <<
".\n";
129 errs() << NameAndArgs.first <<
": Injected args:";
130 for (
int I = 1, E = Args.size();
I < E; ++
I)
131 errs() <<
" " << Args[
I];
134 std::vector<const char *> CLArgs;
135 CLArgs.reserve(Args.size());
136 for (std::string &S : Args)
137 CLArgs.push_back(S.c_str());
144 errs() <<
"*** This tool was not linked to libFuzzer.\n"
145 <<
"*** No fuzzing will be performed.\n";
146 if (
int RC =
Init(&ArgC, &ArgV)) {
147 errs() <<
"Initialization failed\n";
151 for (
int I = 1;
I < ArgC; ++
I) {
154 if (Arg ==
"-ignore_remaining_args=1")
161 if (std::error_code EC = BufOrErr.getError()) {
162 errs() <<
"Error reading file: " << Arg <<
": " << EC.message() <<
"\n";
165 std::unique_ptr<MemoryBuffer> Buf = std::move(BufOrErr.get());
166 errs() <<
"Running: " << Arg <<
" (" << Buf->getBufferSize() <<
" bytes)\n";
167 TestOne(
reinterpret_cast<const uint8_t *
>(Buf->getBufferStart()),
168 Buf->getBufferSize());
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 starts_with(StringRef Prefix) const
Check if this string starts with the given Prefix.
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.