25 std::vector<const char *> CLArgs;
26 CLArgs.push_back(ArgV[0]);
30 if (
StringRef(ArgV[I++]).equals(
"-ignore_remaining_args=1"))
33 CLArgs.push_back(ArgV[I++]);
39 std::vector<std::string>
Args{ExecName};
41 auto NameAndArgs = ExecName.
split(
"--");
42 if (NameAndArgs.second.empty())
46 NameAndArgs.second.split(Opts,
'-');
48 if (Opt.equals(
"gisel")) {
49 Args.push_back(
"-global-isel");
51 Args.push_back(
"-O0");
52 }
else if (Opt.startswith(
"O")) {
53 Args.push_back(
"-" + Opt.str());
55 Args.push_back(
"-mtriple=" + Opt.str());
57 errs() << ExecName <<
": Unknown option: " << Opt <<
".\n";
61 errs() << NameAndArgs.first <<
": Injected args:";
62 for (
int I = 1,
E =
Args.size();
I <
E; ++
I)
66 std::vector<const char *> CLArgs;
67 CLArgs.reserve(
Args.size());
68 for (std::string &S :
Args)
69 CLArgs.push_back(S.c_str());
76 std::vector<std::string>
Args{ExecName};
78 auto NameAndArgs = ExecName.
split(
"--");
79 if (NameAndArgs.second.empty())
83 NameAndArgs.second.split(Opts,
'-');
85 if (Opt ==
"instcombine") {
86 Args.push_back(
"-passes=instcombine");
87 }
else if (Opt ==
"earlycse") {
88 Args.push_back(
"-passes=early-cse");
89 }
else if (Opt ==
"simplifycfg") {
90 Args.push_back(
"-passes=simplify-cfg");
91 }
else if (Opt ==
"gvn") {
92 Args.push_back(
"-passes=gvn");
93 }
else if (Opt ==
"sccp") {
94 Args.push_back(
"-passes=sccp");
96 }
else if (Opt ==
"loop_predication") {
97 Args.push_back(
"-passes=loop-predication");
98 }
else if (Opt ==
"guard_widening") {
99 Args.push_back(
"-passes=guard-widening");
100 }
else if (Opt ==
"loop_rotate") {
101 Args.push_back(
"-passes=loop(rotate)");
102 }
else if (Opt ==
"loop_unswitch") {
103 Args.push_back(
"-passes=loop(unswitch)");
104 }
else if (Opt ==
"loop_unroll") {
105 Args.push_back(
"-passes=unroll");
106 }
else if (Opt ==
"loop_vectorize") {
107 Args.push_back(
"-passes=loop-vectorize");
108 }
else if (Opt ==
"licm") {
109 Args.push_back(
"-passes=licm");
110 }
else if (Opt ==
"indvars") {
111 Args.push_back(
"-passes=indvars");
112 }
else if (Opt ==
"strength_reduce") {
113 Args.push_back(
"-passes=strength-reduce");
114 }
else if (Opt ==
"irce") {
115 Args.push_back(
"-passes=irce");
117 }
else if (
Triple(Opt).getArch()) {
118 Args.push_back(
"-mtriple=" + Opt.str());
120 errs() << ExecName <<
": Unknown option: " << Opt <<
".\n";
125 errs() << NameAndArgs.first <<
": Injected args:";
126 for (
int I = 1,
E =
Args.size();
I <
E; ++
I)
130 std::vector<const char *> CLArgs;
131 CLArgs.reserve(
Args.size());
132 for (std::string &S :
Args)
133 CLArgs.push_back(S.c_str());
140 errs() <<
"*** This tool was not linked to libFuzzer.\n" 141 <<
"*** No fuzzing will be performed.\n";
142 if (
int RC = Init(&ArgC, &ArgV)) {
143 errs() <<
"Initialization failed\n";
147 for (
int I = 1;
I < ArgC; ++
I) {
150 if (Arg.
equals(
"-ignore_remaining_args=1"))
157 if (std::error_code EC = BufOrErr.getError()) {
158 errs() <<
"Error reading file: " << Arg <<
": " << EC.message() <<
"\n";
161 std::unique_ptr<MemoryBuffer> Buf = std::move(BufOrErr.get());
162 errs() <<
"Running: " << Arg <<
" (" << Buf->getBufferSize() <<
" bytes)\n";
163 TestOne(reinterpret_cast<const uint8_t *>(Buf->getBufferStart()),
164 Buf->getBufferSize());
174 return std::make_unique<Module>(
"M",
Context);
177 StringRef(reinterpret_cast<const char *>(Data), Size),
"Fuzzer input",
182 if (
Error E = M.takeError()) {
186 return std::move(M.get());
195 if (Buf.size() > MaxSize)
197 memcpy(Dest, Buf.data(), Buf.size());
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
int(*)(int *argc, char ***argv) FuzzerInitFun
This class represents lattice values for constants.
A Module instance is used to store all the information related to an LLVM module. ...
LLVM_NODISCARD bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
std::unique_ptr< Module > parseAndVerify(const uint8_t *Data, size_t Size, LLVMContext &Context)
Try to parse module and verify it.
static std::unique_ptr< MemoryBuffer > getMemBuffer(StringRef InputData, StringRef BufferName="", bool RequiresNullTerminator=true)
Open the specified memory range as a MemoryBuffer.
size_t writeModule(const Module &M, uint8_t *Dest, size_t MaxSize)
Fuzzer friendly interface for the llvm bitcode printer.
bool ParseCommandLineOptions(int argc, const char *const *argv, StringRef Overview="", raw_ostream *Errs=nullptr, const char *EnvVar=nullptr, bool LongOptionsUseDoubleDash=false)
void handleExecNameEncodedBEOpts(StringRef ExecName)
Handle backend options that are encoded in the executable name.
std::string toString(Error E)
Write all error messages (if any) in E to a string.
void parseFuzzerCLOpts(int ArgC, char *ArgV[])
Parse cl::opts from a fuzz target commandline.
ArchType getArch() const
getArch - Get the parsed architecture type of this triple.
This is an important class for using LLVM in a threaded context.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
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 WriteBitcodeToFile(const Module &M, raw_ostream &Out, bool ShouldPreserveUseListOrder=false, const ModuleSummaryIndex *Index=nullptr, bool GenerateHash=false, ModuleHash *ModHash=nullptr)
Write the specified module to the specified raw output stream.
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
int(*)(const uint8_t *Data, size_t Size) FuzzerTestFun
std::unique_ptr< Module > parseModule(const uint8_t *Data, size_t Size, LLVMContext &Context)
Fuzzer friendly interface for the llvm bitcode parser.
Triple - Helper class for working with autoconf configuration names.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
LLVM_NODISCARD std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
bool verifyModule(const Module &M, raw_ostream *OS=nullptr, bool *BrokenDebugInfo=nullptr)
Check a module for errors.
Expected< std::unique_ptr< Module > > parseBitcodeFile(MemoryBufferRef Buffer, LLVMContext &Context)
Read the specified bitcode file, returning the module.
LLVM_NODISCARD bool equals(StringRef RHS) const
equals - Check for string equality, this is more efficient than compare() when the relative ordering ...
static ErrorOr< std::unique_ptr< MemoryBuffer > > getFile(const Twine &Filename, int64_t FileSize=-1, bool RequiresNullTerminator=true, bool IsVolatile=false)
Open the specified file as a MemoryBuffer, returning a new MemoryBuffer if successful, otherwise returning null.
A raw_ostream that writes to an std::string.
Lightweight error class with error context and mandatory checking.
void handleExecNameEncodedOptimizerOpts(StringRef ExecName)
Handle optimizer options which are encoded in the executable name.
StringRef - Represent a constant reference to a string, i.e.
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
Instances of this class encapsulate one diagnostic report, allowing printing to a raw_ostream as a ca...