[PATCH] D36882: [clang-proto-fuzzer] Allow user-specified compiler arguments.

2017-08-19 Thread Kostya Serebryany via Phabricator via cfe-commits
kcc added a comment.

Update the README file please (with a text similar to this commit message)




Comment at: cfe/trunk/tools/clang-fuzzer/ExampleClangProtoFuzzer.cpp:32
+  for (int I = 1; I < *argc; I++) {
+if (strcmp((*argv)[I], "-ignore_remaining_args=1") == 0) {
+  for (I++; I < *argc; I++)

[remark, feel free to ignore]
the "break;" here is redundant, and thus the {} too, i.e. you can keep the code 
shorter.
Whether it will make it more readable is debatable.  


Repository:
  rL LLVM

https://reviews.llvm.org/D36882



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D36882: [clang-proto-fuzzer] Allow user-specified compiler arguments.

2017-08-18 Thread Matt Morehouse via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL311185: [clang-proto-fuzzer] Allow user-specified compiler 
arguments. (authored by morehouse).

Changed prior to commit:
  https://reviews.llvm.org/D36882?vs=111713=111715#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D36882

Files:
  cfe/trunk/tools/clang-fuzzer/ExampleClangProtoFuzzer.cpp


Index: cfe/trunk/tools/clang-fuzzer/ExampleClangProtoFuzzer.cpp
===
--- cfe/trunk/tools/clang-fuzzer/ExampleClangProtoFuzzer.cpp
+++ cfe/trunk/tools/clang-fuzzer/ExampleClangProtoFuzzer.cpp
@@ -20,9 +20,25 @@
 
 #include "src/libfuzzer/libfuzzer_macro.h"
 
+#include 
+
 using namespace clang_fuzzer;
 
+static std::vector 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);
 }


Index: cfe/trunk/tools/clang-fuzzer/ExampleClangProtoFuzzer.cpp
===
--- cfe/trunk/tools/clang-fuzzer/ExampleClangProtoFuzzer.cpp
+++ cfe/trunk/tools/clang-fuzzer/ExampleClangProtoFuzzer.cpp
@@ -20,9 +20,25 @@
 
 #include "src/libfuzzer/libfuzzer_macro.h"
 
+#include 
+
 using namespace clang_fuzzer;
 
+static std::vector 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);
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D36882: [clang-proto-fuzzer] Allow user-specified compiler arguments.

2017-08-18 Thread Matt Morehouse via Phabricator via cfe-commits
morehouse updated this revision to Diff 111713.
morehouse added a comment.

- Refactor and use strcmp.


https://reviews.llvm.org/D36882

Files:
  clang/tools/clang-fuzzer/ExampleClangProtoFuzzer.cpp


Index: clang/tools/clang-fuzzer/ExampleClangProtoFuzzer.cpp
===
--- clang/tools/clang-fuzzer/ExampleClangProtoFuzzer.cpp
+++ clang/tools/clang-fuzzer/ExampleClangProtoFuzzer.cpp
@@ -20,9 +20,25 @@
 
 #include "src/libfuzzer/libfuzzer_macro.h"
 
+#include 
+
 using namespace clang_fuzzer;
 
+static std::vector 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);
 }


Index: clang/tools/clang-fuzzer/ExampleClangProtoFuzzer.cpp
===
--- clang/tools/clang-fuzzer/ExampleClangProtoFuzzer.cpp
+++ clang/tools/clang-fuzzer/ExampleClangProtoFuzzer.cpp
@@ -20,9 +20,25 @@
 
 #include "src/libfuzzer/libfuzzer_macro.h"
 
+#include 
+
 using namespace clang_fuzzer;
 
+static std::vector 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);
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D36882: [clang-proto-fuzzer] Allow user-specified compiler arguments.

2017-08-18 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka accepted this revision.
vitalybuka added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/tools/clang-fuzzer/ExampleClangProtoFuzzer.cpp:33
+  for (I = 1; I < *argc; I++)
+if (llvm::StringRef((*argv)[I]).equals("-ignore_remaining_args=1"))
+  break;

maybe just strcmp



Comment at: clang/tools/clang-fuzzer/ExampleClangProtoFuzzer.cpp:35
+  break;
+  for (I++; I < *argc; I++)
+CLArgs.push_back((*argv)[I]);

you can put second loop inside of the if just before the break and avoid top 
level var "I"


https://reviews.llvm.org/D36882



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D36882: [clang-proto-fuzzer] Allow user-specified compiler arguments.

2017-08-18 Thread Matt Morehouse via Phabricator via cfe-commits
morehouse created this revision.
Herald added subscribers: kristof.beyls, aemerson.

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


https://reviews.llvm.org/D36882

Files:
  clang/tools/clang-fuzzer/ExampleClangProtoFuzzer.cpp


Index: clang/tools/clang-fuzzer/ExampleClangProtoFuzzer.cpp
===
--- clang/tools/clang-fuzzer/ExampleClangProtoFuzzer.cpp
+++ clang/tools/clang-fuzzer/ExampleClangProtoFuzzer.cpp
@@ -20,9 +20,24 @@
 
 #include "src/libfuzzer/libfuzzer_macro.h"
 
+#include "llvm/ADT/StringRef.h"
+
 using namespace clang_fuzzer;
 
+static std::vector CLArgs;
+
+extern "C" int LLVMFuzzerInitialize(int *argc, char ***argv) {
+  CLArgs.push_back("-O2");
+  int I;
+  for (I = 1; I < *argc; I++)
+if (llvm::StringRef((*argv)[I]).equals("-ignore_remaining_args=1"))
+  break;
+  for (I++; I < *argc; I++)
+CLArgs.push_back((*argv)[I]);
+  return 0;
+}
+
 DEFINE_BINARY_PROTO_FUZZER(const Function& input) {
   auto S = FunctionToString(input);
-  HandleCXX(S, {"-O2"});
+  HandleCXX(S, CLArgs);
 }


Index: clang/tools/clang-fuzzer/ExampleClangProtoFuzzer.cpp
===
--- clang/tools/clang-fuzzer/ExampleClangProtoFuzzer.cpp
+++ clang/tools/clang-fuzzer/ExampleClangProtoFuzzer.cpp
@@ -20,9 +20,24 @@
 
 #include "src/libfuzzer/libfuzzer_macro.h"
 
+#include "llvm/ADT/StringRef.h"
+
 using namespace clang_fuzzer;
 
+static std::vector CLArgs;
+
+extern "C" int LLVMFuzzerInitialize(int *argc, char ***argv) {
+  CLArgs.push_back("-O2");
+  int I;
+  for (I = 1; I < *argc; I++)
+if (llvm::StringRef((*argv)[I]).equals("-ignore_remaining_args=1"))
+  break;
+  for (I++; I < *argc; I++)
+CLArgs.push_back((*argv)[I]);
+  return 0;
+}
+
 DEFINE_BINARY_PROTO_FUZZER(const Function& input) {
   auto S = FunctionToString(input);
-  HandleCXX(S, {"-O2"});
+  HandleCXX(S, CLArgs);
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits