summaryrefslogtreecommitdiffstats
path: root/tools/clang-fuzzer
diff options
context:
space:
mode:
authorMatt Morehouse <mascasa@google.com>2017-08-18 18:34:39 +0000
committerMatt Morehouse <mascasa@google.com>2017-08-18 18:34:39 +0000
commitea3d2bfb45fcdf01672ad827d949e99257242924 (patch)
treefcb63b030c925692a7c45418a6ec47ea6f910798 /tools/clang-fuzzer
parent3acb7796545327967a7f4762cc0412f0d2f11d09 (diff)
[clang-proto-fuzzer] Allow user-specified compiler arguments.
Summary: Arguments can be specified after -ignore_remaining_args=1 to modify the compiler invocation. For example, the following command-line will fuzz LLVM with a custom optimization level and target triple: clang-proto-fuzzer CORPUS/ -ignore_remaining_args -O3 \ -triple arm64-apple-ios9 Reviewers: vitalybuka, kcc Reviewed By: vitalybuka Subscribers: aemerson, cfe-commits, kristof.beyls Differential Revision: https://reviews.llvm.org/D36882 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@311185 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/clang-fuzzer')
-rw-r--r--tools/clang-fuzzer/ExampleClangProtoFuzzer.cpp18
1 files changed, 17 insertions, 1 deletions
diff --git a/tools/clang-fuzzer/ExampleClangProtoFuzzer.cpp b/tools/clang-fuzzer/ExampleClangProtoFuzzer.cpp
index 23123277c3..ab734e85b8 100644
--- a/tools/clang-fuzzer/ExampleClangProtoFuzzer.cpp
+++ b/tools/clang-fuzzer/ExampleClangProtoFuzzer.cpp
@@ -20,9 +20,25 @@
#include "src/libfuzzer/libfuzzer_macro.h"
+#include <cstring>
+
using namespace clang_fuzzer;
+static std::vector<const char *> CLArgs;
+
+extern "C" int LLVMFuzzerInitialize(int *argc, char ***argv) {
+ CLArgs.push_back("-O2");
+ for (int I = 1; I < *argc; I++) {
+ if (strcmp((*argv)[I], "-ignore_remaining_args=1") == 0) {
+ for (I++; I < *argc; I++)
+ CLArgs.push_back((*argv)[I]);
+ break;
+ }
+ }
+ return 0;
+}
+
DEFINE_BINARY_PROTO_FUZZER(const Function& input) {
auto S = FunctionToString(input);
- HandleCXX(S, {"-O2"});
+ HandleCXX(S, CLArgs);
}