26 std::vector<const char *> CLArgs;
27 CLArgs.push_back(ArgV[0]);
31 if (
StringRef(ArgV[I++]).equals(
"-ignore_remaining_args=1"))
34 CLArgs.push_back(ArgV[I++]);
40 std::vector<std::string>
Args{ExecName};
42 auto NameAndArgs = ExecName.
split(
"--");
43 if (NameAndArgs.second.empty())
47 NameAndArgs.second.split(Opts,
'-');
49 if (Opt.equals(
"gisel")) {
50 Args.push_back(
"-global-isel");
52 Args.push_back(
"-O0");
53 }
else if (Opt.startswith(
"O")) {
54 Args.push_back(
"-" + Opt.str());
56 Args.push_back(
"-mtriple=" + Opt.str());
58 errs() << ExecName <<
": Unknown option: " << Opt <<
".\n";
62 errs() << NameAndArgs.first <<
": Injected args:";
63 for (
int I = 1,
E =
Args.size();
I <
E; ++
I)
67 std::vector<const char *> CLArgs;
68 CLArgs.reserve(
Args.size());
69 for (std::string &S :
Args)
70 CLArgs.push_back(S.c_str());
77 std::vector<std::string>
Args{ExecName};
79 auto NameAndArgs = ExecName.
split(
"--");
80 if (NameAndArgs.second.empty())
84 NameAndArgs.second.split(Opts,
'-');
86 if (Opt ==
"instcombine") {
87 Args.push_back(
"-passes=instcombine");
88 }
else if (Opt ==
"earlycse") {
89 Args.push_back(
"-passes=early-cse");
90 }
else if (Opt ==
"simplifycfg") {
91 Args.push_back(
"-passes=simplify-cfg");
92 }
else if (Opt ==
"gvn") {
93 Args.push_back(
"-passes=gvn");
94 }
else if (Opt ==
"sccp") {
95 Args.push_back(
"-passes=sccp");
97 }
else if (Opt ==
"loop_predication") {
98 Args.push_back(
"-passes=loop-predication");
99 }
else if (Opt ==
"guard_widening") {
100 Args.push_back(
"-passes=guard-widening");
101 }
else if (Opt ==
"loop_rotate") {
102 Args.push_back(
"-passes=loop(rotate)");
103 }
else if (Opt ==
"loop_unswitch") {
104 Args.push_back(
"-passes=loop(unswitch)");
105 }
else if (Opt ==
"loop_unroll") {
106 Args.push_back(
"-passes=unroll");
107 }
else if (Opt ==
"loop_vectorize") {
108 Args.push_back(
"-passes=loop-vectorize");
109 }
else if (Opt ==
"licm") {
110 Args.push_back(
"-passes=licm");
111 }
else if (Opt ==
"indvars") {
112 Args.push_back(
"-passes=indvars");
113 }
else if (Opt ==
"strength_reduce") {
114 Args.push_back(
"-passes=strength-reduce");
115 }
else if (Opt ==
"irce") {
116 Args.push_back(
"-passes=irce");
118 }
else if (
Triple(Opt).getArch()) {
119 Args.push_back(
"-mtriple=" + Opt.str());
121 errs() << ExecName <<
": Unknown option: " << Opt <<
".\n";
126 errs() << NameAndArgs.first <<
": Injected args:";
127 for (
int I = 1,
E =
Args.size();
I <
E; ++
I)
131 std::vector<const char *> CLArgs;
132 CLArgs.reserve(
Args.size());
133 for (std::string &S :
Args)
134 CLArgs.push_back(S.c_str());
141 errs() <<
"*** This tool was not linked to libFuzzer.\n" 142 <<
"*** No fuzzing will be performed.\n";
143 if (
int RC = Init(&ArgC, &ArgV)) {
144 errs() <<
"Initialization failed\n";
148 for (
int I = 1;
I < ArgC; ++
I) {
151 if (Arg.
equals(
"-ignore_remaining_args=1"))
158 if (std::error_code EC = BufOrErr.getError()) {
159 errs() <<
"Error reading file: " << Arg <<
": " << EC.message() <<
"\n";
162 std::unique_ptr<MemoryBuffer> Buf = std::move(BufOrErr.get());
163 errs() <<
"Running: " << Arg <<
" (" << Buf->getBufferSize() <<
" bytes)\n";
164 TestOne(reinterpret_cast<const uint8_t *>(Buf->getBufferStart()),
165 Buf->getBufferSize());
175 return llvm::make_unique<Module>(
"M",
Context);
178 StringRef(reinterpret_cast<const char *>(Data), Size),
"Fuzzer input",
183 if (
Error E = M.takeError()) {
187 return std::move(M.get());
196 if (Buf.size() > MaxSize)
198 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. ...
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.
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.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
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.
bool ParseCommandLineOptions(int argc, const char *const *argv, StringRef Overview="", raw_ostream *Errs=nullptr, const char *EnvVar=nullptr)
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.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool equals(StringRef RHS) const
equals - Check for string equality, this is more efficient than compare() when the relative ordering ...
bool verifyModule(const Module &M, raw_ostream *OS=nullptr, bool *BrokenDebugInfo=nullptr)
Check a module for errors.
amdgpu Simplify well known AMD library false Value Value * Arg
Expected< std::unique_ptr< Module > > parseBitcodeFile(MemoryBufferRef Buffer, LLVMContext &Context)
Read the specified bitcode file, returning the module.
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...