[PATCH] D47666: Refactored clang-fuzzer and added new (copy) files

2018-06-07 Thread Kostya Serebryany via Phabricator via cfe-commits
kcc added a comment.

Some feedback on the generated code:

  while (1){

let's not have the while loops inside the for loops for now. 
If the initial goal is to stress the loop optimizations (e.g. vectorizer), 
loops likes this are just a distraction

  for (int loop_ctr = 0

too verbose. Use 'i'm 'j', 'k'
also, alternate int, unsigned, size_t, long (later).

  a[436863498 % s]=1;

this is good for keeping the code UB-free, but it will render the tests 
non-vectorizable. 
need more tests that won't use `% s`

  void foo(int *a, size_t s) {

ok for a starter, but will need a more rich signature in the future versions.


Repository:
  rL LLVM

https://reviews.llvm.org/D47666



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


[PATCH] D47666: Refactored clang-fuzzer and added new (copy) files

2018-06-04 Thread Matt Morehouse via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL333969: [clang-proto-fuzzer] Refactored LLVMFuzzerInitialize 
into its own file. (authored by morehouse, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D47666?vs=149872&id=149876#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D47666

Files:
  cfe/trunk/tools/clang-fuzzer/CMakeLists.txt
  cfe/trunk/tools/clang-fuzzer/ExampleClangProtoFuzzer.cpp
  cfe/trunk/tools/clang-fuzzer/fuzzer-initialize/CMakeLists.txt
  cfe/trunk/tools/clang-fuzzer/fuzzer-initialize/fuzzer_initialize.cpp
  cfe/trunk/tools/clang-fuzzer/fuzzer-initialize/fuzzer_initialize.h

Index: cfe/trunk/tools/clang-fuzzer/CMakeLists.txt
===
--- cfe/trunk/tools/clang-fuzzer/CMakeLists.txt
+++ cfe/trunk/tools/clang-fuzzer/CMakeLists.txt
@@ -40,6 +40,9 @@
   # Build the protobuf->C++ translation library and driver.
   add_clang_subdirectory(proto-to-cxx)
 
+  # Build the fuzzer initialization library.
+  add_clang_subdirectory(fuzzer-initialize)
+
   # Build the protobuf fuzzer
   add_clang_executable(clang-proto-fuzzer
 ${DUMMY_MAIN}
@@ -52,6 +55,7 @@
 ${PROTOBUF_LIBRARIES}
 ${LLVM_LIB_FUZZING_ENGINE}
 clangCXXProto
+clangFuzzerInitialize
 clangHandleCXX
 clangProtoToCXX
 )
Index: cfe/trunk/tools/clang-fuzzer/ExampleClangProtoFuzzer.cpp
===
--- cfe/trunk/tools/clang-fuzzer/ExampleClangProtoFuzzer.cpp
+++ cfe/trunk/tools/clang-fuzzer/ExampleClangProtoFuzzer.cpp
@@ -17,28 +17,12 @@
 #include "cxx_proto.pb.h"
 #include "handle-cxx/handle_cxx.h"
 #include "proto-to-cxx/proto_to_cxx.h"
-
+#include "fuzzer-initialize/fuzzer_initialize.h"
 #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, CLArgs);
+  HandleCXX(S, GetCLArgs());
 }
Index: cfe/trunk/tools/clang-fuzzer/fuzzer-initialize/fuzzer_initialize.h
===
--- cfe/trunk/tools/clang-fuzzer/fuzzer-initialize/fuzzer_initialize.h
+++ cfe/trunk/tools/clang-fuzzer/fuzzer-initialize/fuzzer_initialize.h
@@ -0,0 +1,19 @@
+//==-- fuzzer_initialize.h - Fuzz Clang ==//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// Defines a function that returns the command line arguments for a specific
+// call to the fuzz target.
+//
+//===--===//
+
+#include 
+
+namespace clang_fuzzer {
+const std::vector& GetCLArgs();
+}
Index: cfe/trunk/tools/clang-fuzzer/fuzzer-initialize/fuzzer_initialize.cpp
===
--- cfe/trunk/tools/clang-fuzzer/fuzzer-initialize/fuzzer_initialize.cpp
+++ cfe/trunk/tools/clang-fuzzer/fuzzer-initialize/fuzzer_initialize.cpp
@@ -0,0 +1,43 @@
+//===-- fuzzer_initialize.cpp - Fuzz Clang ===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+///
+/// \file
+/// This file implements two functions: one that returns the command line
+/// arguments for a given call to the fuzz target and one that initializes
+/// the fuzzer with the correct command line arguments.
+///
+//===--===//
+
+#include "fuzzer_initialize.h"
+#include 
+
+using namespace clang_fuzzer;
+
+
+namespace clang_fuzzer {
+
+static std::vector CLArgs;
+
+const std::vector& GetCLArgs() {
+  return 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;
+}
Index: cfe/trunk/tools/clang-fuzzer/fuzzer-initialize/CMakeLists.txt
===
--- cfe/trunk/tools/clang-fuzzer/fuzzer-initialize/CMakeLists.txt
+++ cfe/trunk/tools/cla

[PATCH] D47666: Refactored clang-fuzzer and added new (copy) files

2018-06-04 Thread Matt Morehouse via Phabricator via cfe-commits
morehouse accepted this revision.
morehouse added a comment.

LGTM.


Repository:
  rC Clang

https://reviews.llvm.org/D47666



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


[PATCH] D47666: Refactored clang-fuzzer and added new (copy) files

2018-06-04 Thread Emmett Neyman via Phabricator via cfe-commits
emmettneyman updated this revision to Diff 149872.
emmettneyman added a comment.

- Removed unecessary includes and renamed library.


Repository:
  rC Clang

https://reviews.llvm.org/D47666

Files:
  tools/clang-fuzzer/CMakeLists.txt
  tools/clang-fuzzer/ExampleClangProtoFuzzer.cpp
  tools/clang-fuzzer/fuzzer-initialize/CMakeLists.txt
  tools/clang-fuzzer/fuzzer-initialize/fuzzer_initialize.cpp
  tools/clang-fuzzer/fuzzer-initialize/fuzzer_initialize.h

Index: tools/clang-fuzzer/fuzzer-initialize/fuzzer_initialize.h
===
--- /dev/null
+++ tools/clang-fuzzer/fuzzer-initialize/fuzzer_initialize.h
@@ -0,0 +1,20 @@
+//==-- fuzzer_initialize.h - Fuzz Clang ==//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// Defines a function that returns the command line arguments for a specific
+// call to the fuzz target.
+//
+//===--===//
+
+#include 
+
+namespace clang_fuzzer {
+const std::vector& GetCLArgs();
+}
+
Index: tools/clang-fuzzer/fuzzer-initialize/fuzzer_initialize.cpp
===
--- tools/clang-fuzzer/fuzzer-initialize/fuzzer_initialize.cpp
+++ tools/clang-fuzzer/fuzzer-initialize/fuzzer_initialize.cpp
@@ -1,4 +1,4 @@
-//===-- ExampleClangProtoFuzzer.cpp - Fuzz Clang --===//
+//===-- fuzzer_initialize.cpp - Fuzz Clang ===//
 //
 // The LLVM Compiler Infrastructure
 //
@@ -8,24 +8,28 @@
 //===--===//
 ///
 /// \file
-/// This file implements a function that runs Clang on a single
-///  input and uses libprotobuf-mutator to find new inputs. This function is
-///  then linked into the Fuzzer library.
+/// This file implements two functions: one that returns the command line 
+/// arguments for a given call to the fuzz target and one that initializes
+/// the fuzzer with the correct command line arguments. 
 ///
 //===--===//
 
-#include "cxx_proto.pb.h"
-#include "handle-cxx/handle_cxx.h"
-#include "proto-to-cxx/proto_to_cxx.h"
-
-#include "src/libfuzzer/libfuzzer_macro.h"
-
+#include "fuzzer_initialize.h"
 #include 
 
 using namespace clang_fuzzer;
 
+
+namespace clang_fuzzer {
+
 static std::vector CLArgs;
 
+const std::vector& GetCLArgs() {
+  return CLArgs;
+}
+
+}
+
 extern "C" int LLVMFuzzerInitialize(int *argc, char ***argv) {
   CLArgs.push_back("-O2");
   for (int I = 1; I < *argc; I++) {
@@ -38,7 +42,3 @@
   return 0;
 }
 
-DEFINE_BINARY_PROTO_FUZZER(const Function& input) {
-  auto S = FunctionToString(input);
-  HandleCXX(S, CLArgs);
-}
Index: tools/clang-fuzzer/fuzzer-initialize/CMakeLists.txt
===
--- /dev/null
+++ tools/clang-fuzzer/fuzzer-initialize/CMakeLists.txt
@@ -0,0 +1,3 @@
+set(LLVM_LINK_COMPONENTS ${LLVM_TARGETS_TO_BUILD} Support)
+
+add_clang_library(clangFuzzerInitialize fuzzer_initialize.cpp)
Index: tools/clang-fuzzer/ExampleClangProtoFuzzer.cpp
===
--- tools/clang-fuzzer/ExampleClangProtoFuzzer.cpp
+++ tools/clang-fuzzer/ExampleClangProtoFuzzer.cpp
@@ -17,28 +17,12 @@
 #include "cxx_proto.pb.h"
 #include "handle-cxx/handle_cxx.h"
 #include "proto-to-cxx/proto_to_cxx.h"
-
+#include "fuzzer-initialize/fuzzer_initialize.h"
 #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, CLArgs);
+  HandleCXX(S, GetCLArgs());
 }
Index: tools/clang-fuzzer/CMakeLists.txt
===
--- tools/clang-fuzzer/CMakeLists.txt
+++ tools/clang-fuzzer/CMakeLists.txt
@@ -39,6 +39,9 @@
 
   # Build the protobuf->C++ translation library and driver.
   add_clang_subdirectory(proto-to-cxx)
+  
+  # Build the fuzzer initialization library.
+  add_clang_subdirectory(fuzzer-initialize)
 
   # Build the protobuf fuzzer
   add_clang_executable(clang-proto-fuzzer
@@ -52,6 +55,7 @@
 ${PROTOBUF_LIBRARIES}
 ${LLVM_LIB_FUZZING_ENGINE}
 clangCXXProto
+clangFuzzerInitialize
 clangHandleCXX
 clangProt

[PATCH] D47666: Refactored clang-fuzzer and added new (copy) files

2018-06-04 Thread Matt Morehouse via Phabricator via cfe-commits
morehouse added inline comments.



Comment at: tools/clang-fuzzer/ExampleClangProtoFuzzer.cpp:23
 
 #include 
 

I think `cstring` is no longer used after this change.  So we can probably 
remove this include.



Comment at: tools/clang-fuzzer/fuzzer-initialize/CMakeLists.txt:3
+
+add_clang_library(clangFuzzerInit fuzzer_initialize.cpp)

Nit:  `clangFuzzerInitialize` would better follow the naming convention of the 
other libraries.



Comment at: tools/clang-fuzzer/fuzzer-initialize/fuzzer_initialize.h:15
+
+#include "src/libfuzzer/libfuzzer_macro.h"
+

I don't think this include is used in this file either.  Can we remove it?


Repository:
  rC Clang

https://reviews.llvm.org/D47666



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


[PATCH] D47666: Refactored clang-fuzzer and added new (copy) files

2018-06-04 Thread Emmett Neyman via Phabricator via cfe-commits
emmettneyman updated this revision to Diff 149867.
emmettneyman added a comment.

- Refactored FuzzerInitialize into library


Repository:
  rC Clang

https://reviews.llvm.org/D47666

Files:
  tools/clang-fuzzer/CMakeLists.txt
  tools/clang-fuzzer/ExampleClangProtoFuzzer.cpp
  tools/clang-fuzzer/fuzzer-initialize/CMakeLists.txt
  tools/clang-fuzzer/fuzzer-initialize/fuzzer_initialize.cpp
  tools/clang-fuzzer/fuzzer-initialize/fuzzer_initialize.h

Index: tools/clang-fuzzer/fuzzer-initialize/fuzzer_initialize.h
===
--- /dev/null
+++ tools/clang-fuzzer/fuzzer-initialize/fuzzer_initialize.h
@@ -0,0 +1,20 @@
+//==-- fuzzer_initialize.h - Fuzz Clang ==//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// Defines a function that returns the command line arguments for a specific
+// call to the fuzz target.
+//
+//===--===//
+
+#include "src/libfuzzer/libfuzzer_macro.h"
+
+namespace clang_fuzzer {
+const std::vector& GetCLArgs();
+}
+
Index: tools/clang-fuzzer/fuzzer-initialize/fuzzer_initialize.cpp
===
--- tools/clang-fuzzer/fuzzer-initialize/fuzzer_initialize.cpp
+++ tools/clang-fuzzer/fuzzer-initialize/fuzzer_initialize.cpp
@@ -1,4 +1,4 @@
-//===-- ExampleClangProtoFuzzer.cpp - Fuzz Clang --===//
+//===-- fuzzer_initialize.cpp - Fuzz Clang ===//
 //
 // The LLVM Compiler Infrastructure
 //
@@ -8,24 +8,27 @@
 //===--===//
 ///
 /// \file
-/// This file implements a function that runs Clang on a single
-///  input and uses libprotobuf-mutator to find new inputs. This function is
-///  then linked into the Fuzzer library.
+/// This file implements two functions: one that returns the command line 
+/// arguments for a given call to the fuzz target and one that initializes
+/// the fuzzer with the correct command line arguments. 
 ///
 //===--===//
 
-#include "cxx_proto.pb.h"
-#include "handle-cxx/handle_cxx.h"
-#include "proto-to-cxx/proto_to_cxx.h"
+#include "fuzzer_initialize.h"
 
-#include "src/libfuzzer/libfuzzer_macro.h"
+using namespace clang_fuzzer;
 
-#include 
 
-using namespace clang_fuzzer;
+namespace clang_fuzzer {
 
 static std::vector CLArgs;
 
+const std::vector& GetCLArgs() {
+  return CLArgs;
+}
+
+}
+
 extern "C" int LLVMFuzzerInitialize(int *argc, char ***argv) {
   CLArgs.push_back("-O2");
   for (int I = 1; I < *argc; I++) {
@@ -38,7 +41,3 @@
   return 0;
 }
 
-DEFINE_BINARY_PROTO_FUZZER(const Function& input) {
-  auto S = FunctionToString(input);
-  HandleCXX(S, CLArgs);
-}
Index: tools/clang-fuzzer/fuzzer-initialize/CMakeLists.txt
===
--- /dev/null
+++ tools/clang-fuzzer/fuzzer-initialize/CMakeLists.txt
@@ -0,0 +1,3 @@
+set(LLVM_LINK_COMPONENTS ${LLVM_TARGETS_TO_BUILD} Support)
+
+add_clang_library(clangFuzzerInit fuzzer_initialize.cpp)
Index: tools/clang-fuzzer/ExampleClangProtoFuzzer.cpp
===
--- tools/clang-fuzzer/ExampleClangProtoFuzzer.cpp
+++ tools/clang-fuzzer/ExampleClangProtoFuzzer.cpp
@@ -17,28 +17,14 @@
 #include "cxx_proto.pb.h"
 #include "handle-cxx/handle_cxx.h"
 #include "proto-to-cxx/proto_to_cxx.h"
-
+#include "fuzzer-initialize/fuzzer_initialize.h"
 #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, CLArgs);
+  HandleCXX(S, GetCLArgs());
 }
Index: tools/clang-fuzzer/CMakeLists.txt
===
--- tools/clang-fuzzer/CMakeLists.txt
+++ tools/clang-fuzzer/CMakeLists.txt
@@ -39,6 +39,9 @@
 
   # Build the protobuf->C++ translation library and driver.
   add_clang_subdirectory(proto-to-cxx)
+  
+  # Build the fuzzer initialization library.
+  add_clang_subdirectory(fuzzer-initialize)
 
   # Build the protobuf fuzzer
   add_clang_executable(clang-proto-fuzzer
@@ -52,6 +55,7 @@
 ${PROTOBUF_LIBRARIES}
 ${LLVM_LIB_FUZZING_ENGINE}
 clangCXXProto
+clangFuzze

[PATCH] D47666: Refactored clang-fuzzer and added new (copy) files

2018-06-04 Thread Matt Morehouse via Phabricator via cfe-commits
morehouse added inline comments.



Comment at: tools/clang-fuzzer/CMakeLists.txt:48
 ExampleClangProtoFuzzer.cpp
+FuzzerInitialize.cpp
 )

Rather than compiling `FuzzerInitialize.cpp` into the binary, can we make it a 
library like `handle-cxx` or `proto-to-cxx`?



Comment at: tools/clang-fuzzer/FuzzerInitialize.cpp:17
 
 #include "cxx_proto.pb.h"
 

Do we need this include?



Comment at: tools/clang-fuzzer/FuzzerInitialize.h:20
+
+#include 
+

Why do we need these includes in the header?  Doesn't look like they're used 
here.


Repository:
  rC Clang

https://reviews.llvm.org/D47666



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


[PATCH] D47666: Refactored clang-fuzzer and added new (copy) files

2018-06-04 Thread Emmett Neyman via Phabricator via cfe-commits
emmettneyman added a comment.

In https://reviews.llvm.org/D47666#1121608, @emmettneyman wrote:

> - Updated and added header comments to two new files. Deleted loop fuzzer 
> files.


I will commit the loop fuzzer files in a future patch.


Repository:
  rC Clang

https://reviews.llvm.org/D47666



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


[PATCH] D47666: Refactored clang-fuzzer and added new (copy) files

2018-06-04 Thread Emmett Neyman via Phabricator via cfe-commits
emmettneyman updated this revision to Diff 149854.
emmettneyman added a comment.

- Another edit to the file header comments.


Repository:
  rC Clang

https://reviews.llvm.org/D47666

Files:
  tools/clang-fuzzer/CMakeLists.txt
  tools/clang-fuzzer/ExampleClangProtoFuzzer.cpp
  tools/clang-fuzzer/FuzzerInitialize.cpp
  tools/clang-fuzzer/FuzzerInitialize.h

Index: tools/clang-fuzzer/FuzzerInitialize.h
===
--- /dev/null
+++ tools/clang-fuzzer/FuzzerInitialize.h
@@ -0,0 +1,25 @@
+//==-- FuzzerInitialize.h - Fuzz Clang -==//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// Defines a function that returns the command line arguments for a specific
+// call to the fuzz target.
+//
+//===--===//
+
+#include "handle-cxx/handle_cxx.h"
+#include "proto-to-cxx/proto_to_cxx.h"
+
+#include "src/libfuzzer/libfuzzer_macro.h"
+
+#include 
+
+namespace clang_fuzzer {
+const std::vector& GetCLArgs();
+}
+
Index: tools/clang-fuzzer/FuzzerInitialize.cpp
===
--- tools/clang-fuzzer/FuzzerInitialize.cpp
+++ tools/clang-fuzzer/FuzzerInitialize.cpp
@@ -1,4 +1,4 @@
-//===-- ExampleClangProtoFuzzer.cpp - Fuzz Clang --===//
+//===-- FuzzerInitialize.cpp - Fuzz Clang -===//
 //
 // The LLVM Compiler Infrastructure
 //
@@ -8,24 +8,29 @@
 //===--===//
 ///
 /// \file
-/// This file implements a function that runs Clang on a single
-///  input and uses libprotobuf-mutator to find new inputs. This function is
-///  then linked into the Fuzzer library.
+/// This file implements two functions: one that returns the command line 
+/// arguments for a given call to the fuzz target and one that initializes
+/// the fuzzer with the correct command line arguments. 
 ///
 //===--===//
 
 #include "cxx_proto.pb.h"
-#include "handle-cxx/handle_cxx.h"
-#include "proto-to-cxx/proto_to_cxx.h"
 
-#include "src/libfuzzer/libfuzzer_macro.h"
-
-#include 
+#include "FuzzerInitialize.h"
 
 using namespace clang_fuzzer;
 
+
+namespace clang_fuzzer {
+
 static std::vector CLArgs;
 
+const std::vector& GetCLArgs() {
+  return CLArgs;
+}
+
+}
+
 extern "C" int LLVMFuzzerInitialize(int *argc, char ***argv) {
   CLArgs.push_back("-O2");
   for (int I = 1; I < *argc; I++) {
@@ -38,7 +43,3 @@
   return 0;
 }
 
-DEFINE_BINARY_PROTO_FUZZER(const Function& input) {
-  auto S = FunctionToString(input);
-  HandleCXX(S, CLArgs);
-}
Index: tools/clang-fuzzer/ExampleClangProtoFuzzer.cpp
===
--- tools/clang-fuzzer/ExampleClangProtoFuzzer.cpp
+++ tools/clang-fuzzer/ExampleClangProtoFuzzer.cpp
@@ -18,27 +18,14 @@
 #include "handle-cxx/handle_cxx.h"
 #include "proto-to-cxx/proto_to_cxx.h"
 
+#include "FuzzerInitialize.h"
 #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, CLArgs);
+  HandleCXX(S, GetCLArgs());
 }
Index: tools/clang-fuzzer/CMakeLists.txt
===
--- tools/clang-fuzzer/CMakeLists.txt
+++ tools/clang-fuzzer/CMakeLists.txt
@@ -14,6 +14,7 @@
   ClangFuzzer.cpp
   DummyClangFuzzer.cpp
   ExampleClangProtoFuzzer.cpp
+  FuzzerInitialize.cpp
   )
 
 if(CLANG_ENABLE_PROTO_FUZZER)
@@ -44,6 +45,7 @@
   add_clang_executable(clang-proto-fuzzer
 ${DUMMY_MAIN}
 ExampleClangProtoFuzzer.cpp
+FuzzerInitialize.cpp
 )
 
   target_link_libraries(clang-proto-fuzzer
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D47666: Refactored clang-fuzzer and added new (copy) files

2018-06-04 Thread Emmett Neyman via Phabricator via cfe-commits
emmettneyman updated this revision to Diff 149851.
emmettneyman added a comment.

- Fixed file header comment


Repository:
  rC Clang

https://reviews.llvm.org/D47666

Files:
  tools/clang-fuzzer/CMakeLists.txt
  tools/clang-fuzzer/ExampleClangProtoFuzzer.cpp
  tools/clang-fuzzer/FuzzerInitialize.cpp
  tools/clang-fuzzer/FuzzerInitialize.h

Index: tools/clang-fuzzer/FuzzerInitialize.h
===
--- /dev/null
+++ tools/clang-fuzzer/FuzzerInitialize.h
@@ -0,0 +1,25 @@
+//==-- FuzzerInitialize.h - Protobuf-C++ conversion ==//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// Defines a function that returns the command line arguments for a specific
+// call to the fuzz target.
+//
+//===--===//
+
+#include "handle-cxx/handle_cxx.h"
+#include "proto-to-cxx/proto_to_cxx.h"
+
+#include "src/libfuzzer/libfuzzer_macro.h"
+
+#include 
+
+namespace clang_fuzzer {
+const std::vector& GetCLArgs();
+}
+
Index: tools/clang-fuzzer/FuzzerInitialize.cpp
===
--- tools/clang-fuzzer/FuzzerInitialize.cpp
+++ tools/clang-fuzzer/FuzzerInitialize.cpp
@@ -1,4 +1,4 @@
-//===-- ExampleClangProtoFuzzer.cpp - Fuzz Clang --===//
+//===-- FuzzerInitialize.cpp - Fuzz Clang -===//
 //
 // The LLVM Compiler Infrastructure
 //
@@ -8,24 +8,29 @@
 //===--===//
 ///
 /// \file
-/// This file implements a function that runs Clang on a single
-///  input and uses libprotobuf-mutator to find new inputs. This function is
-///  then linked into the Fuzzer library.
+/// This file implements two functions: one that returns the command line 
+/// arguments for a given call to the fuzz target and one that initializes
+/// the fuzzer with the correct command line arguments. 
 ///
 //===--===//
 
 #include "cxx_proto.pb.h"
-#include "handle-cxx/handle_cxx.h"
-#include "proto-to-cxx/proto_to_cxx.h"
 
-#include "src/libfuzzer/libfuzzer_macro.h"
-
-#include 
+#include "FuzzerInitialize.h"
 
 using namespace clang_fuzzer;
 
+
+namespace clang_fuzzer {
+
 static std::vector CLArgs;
 
+const std::vector& GetCLArgs() {
+  return CLArgs;
+}
+
+}
+
 extern "C" int LLVMFuzzerInitialize(int *argc, char ***argv) {
   CLArgs.push_back("-O2");
   for (int I = 1; I < *argc; I++) {
@@ -38,7 +43,3 @@
   return 0;
 }
 
-DEFINE_BINARY_PROTO_FUZZER(const Function& input) {
-  auto S = FunctionToString(input);
-  HandleCXX(S, CLArgs);
-}
Index: tools/clang-fuzzer/ExampleClangProtoFuzzer.cpp
===
--- tools/clang-fuzzer/ExampleClangProtoFuzzer.cpp
+++ tools/clang-fuzzer/ExampleClangProtoFuzzer.cpp
@@ -18,27 +18,14 @@
 #include "handle-cxx/handle_cxx.h"
 #include "proto-to-cxx/proto_to_cxx.h"
 
+#include "FuzzerInitialize.h"
 #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, CLArgs);
+  HandleCXX(S, GetCLArgs());
 }
Index: tools/clang-fuzzer/CMakeLists.txt
===
--- tools/clang-fuzzer/CMakeLists.txt
+++ tools/clang-fuzzer/CMakeLists.txt
@@ -14,6 +14,7 @@
   ClangFuzzer.cpp
   DummyClangFuzzer.cpp
   ExampleClangProtoFuzzer.cpp
+  FuzzerInitialize.cpp
   )
 
 if(CLANG_ENABLE_PROTO_FUZZER)
@@ -44,6 +45,7 @@
   add_clang_executable(clang-proto-fuzzer
 ${DUMMY_MAIN}
 ExampleClangProtoFuzzer.cpp
+FuzzerInitialize.cpp
 )
 
   target_link_libraries(clang-proto-fuzzer
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D47666: Refactored clang-fuzzer and added new (copy) files

2018-06-04 Thread Emmett Neyman via Phabricator via cfe-commits
emmettneyman updated this revision to Diff 149850.
emmettneyman added a comment.

- Updated and added header comments to two new files. Deleted loop fuzzer files.


Repository:
  rC Clang

https://reviews.llvm.org/D47666

Files:
  tools/clang-fuzzer/CMakeLists.txt
  tools/clang-fuzzer/ExampleClangProtoFuzzer.cpp
  tools/clang-fuzzer/FuzzerInitialize.cpp
  tools/clang-fuzzer/FuzzerInitialize.h

Index: tools/clang-fuzzer/FuzzerInitialize.h
===
--- /dev/null
+++ tools/clang-fuzzer/FuzzerInitialize.h
@@ -0,0 +1,25 @@
+//==-- proto_to_cxx.h - Protobuf-C++ conversion ==//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// Defines a function that returns the command line arguments for a specific
+// call to the fuzz target.
+//
+//===--===//
+
+#include "handle-cxx/handle_cxx.h"
+#include "proto-to-cxx/proto_to_cxx.h"
+
+#include "src/libfuzzer/libfuzzer_macro.h"
+
+#include 
+
+namespace clang_fuzzer {
+const std::vector& GetCLArgs();
+}
+
Index: tools/clang-fuzzer/FuzzerInitialize.cpp
===
--- tools/clang-fuzzer/FuzzerInitialize.cpp
+++ tools/clang-fuzzer/FuzzerInitialize.cpp
@@ -1,4 +1,4 @@
-//===-- ExampleClangProtoFuzzer.cpp - Fuzz Clang --===//
+//===-- FuzzerInitialize.cpp - Fuzz Clang -===//
 //
 // The LLVM Compiler Infrastructure
 //
@@ -8,24 +8,29 @@
 //===--===//
 ///
 /// \file
-/// This file implements a function that runs Clang on a single
-///  input and uses libprotobuf-mutator to find new inputs. This function is
-///  then linked into the Fuzzer library.
+/// This file implements two functions: one that returns the command line 
+/// arguments for a given call to the fuzz target and one that initializes
+/// the fuzzer with the correct command line arguments. 
 ///
 //===--===//
 
 #include "cxx_proto.pb.h"
-#include "handle-cxx/handle_cxx.h"
-#include "proto-to-cxx/proto_to_cxx.h"
 
-#include "src/libfuzzer/libfuzzer_macro.h"
-
-#include 
+#include "FuzzerInitialize.h"
 
 using namespace clang_fuzzer;
 
+
+namespace clang_fuzzer {
+
 static std::vector CLArgs;
 
+const std::vector& GetCLArgs() {
+  return CLArgs;
+}
+
+}
+
 extern "C" int LLVMFuzzerInitialize(int *argc, char ***argv) {
   CLArgs.push_back("-O2");
   for (int I = 1; I < *argc; I++) {
@@ -38,7 +43,3 @@
   return 0;
 }
 
-DEFINE_BINARY_PROTO_FUZZER(const Function& input) {
-  auto S = FunctionToString(input);
-  HandleCXX(S, CLArgs);
-}
Index: tools/clang-fuzzer/ExampleClangProtoFuzzer.cpp
===
--- tools/clang-fuzzer/ExampleClangProtoFuzzer.cpp
+++ tools/clang-fuzzer/ExampleClangProtoFuzzer.cpp
@@ -18,27 +18,14 @@
 #include "handle-cxx/handle_cxx.h"
 #include "proto-to-cxx/proto_to_cxx.h"
 
+#include "FuzzerInitialize.h"
 #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, CLArgs);
+  HandleCXX(S, GetCLArgs());
 }
Index: tools/clang-fuzzer/CMakeLists.txt
===
--- tools/clang-fuzzer/CMakeLists.txt
+++ tools/clang-fuzzer/CMakeLists.txt
@@ -14,6 +14,7 @@
   ClangFuzzer.cpp
   DummyClangFuzzer.cpp
   ExampleClangProtoFuzzer.cpp
+  FuzzerInitialize.cpp
   )
 
 if(CLANG_ENABLE_PROTO_FUZZER)
@@ -44,6 +45,7 @@
   add_clang_executable(clang-proto-fuzzer
 ${DUMMY_MAIN}
 ExampleClangProtoFuzzer.cpp
+FuzzerInitialize.cpp
 )
 
   target_link_libraries(clang-proto-fuzzer
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D47666: Refactored clang-fuzzer and added new (copy) files

2018-06-04 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka requested changes to this revision.
vitalybuka added inline comments.
This revision now requires changes to proceed.



Comment at: tools/clang-fuzzer/FuzzerInitialize.cpp:11
 /// \file
 /// This file implements a function that runs Clang on a single
 ///  input and uses libprotobuf-mutator to find new inputs. This function is

Could you please update this description?



Comment at: tools/clang-fuzzer/experimental/ExampleClangLoopProtoFuzzer.cpp:22
+
+#include "FuzzerInitialize.h"
 

Please move ExampleClangLoopProtoFuzzer into a separate patch


Repository:
  rC Clang

https://reviews.llvm.org/D47666



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


[PATCH] D47666: Refactored clang-fuzzer and added new (copy) files

2018-06-04 Thread Emmett Neyman via Phabricator via cfe-commits
emmettneyman updated this revision to Diff 149807.
emmettneyman added a comment.

- Changed CLArgs into getter and deleted commented code

1. Updating https://reviews.llvm.org/D47666: Refactored clang-fuzzer and added 
new (copy) files #
2. Enter a brief description of the changes included in this update.
3. The first line is used as subject, next lines as comment.

Made changes in response to comments
Removed commented out code
Changed CLArgs to be a getter method
Removed LLVMFuzzerInitialize decl from header file


Repository:
  rC Clang

https://reviews.llvm.org/D47666

Files:
  tools/clang-fuzzer/CMakeLists.txt
  tools/clang-fuzzer/ExampleClangProtoFuzzer.cpp
  tools/clang-fuzzer/FuzzerInitialize.cpp
  tools/clang-fuzzer/FuzzerInitialize.h
  tools/clang-fuzzer/experimental/ExampleClangLoopProtoFuzzer.cpp
  tools/clang-fuzzer/experimental/cxx_loop_proto.proto
  tools/clang-fuzzer/proto-to-cxx/experimental/loop_proto_to_cxx.cpp
  tools/clang-fuzzer/proto-to-cxx/experimental/loop_proto_to_cxx.h
  tools/clang-fuzzer/proto-to-cxx/experimental/loop_proto_to_cxx_main.cpp

Index: tools/clang-fuzzer/proto-to-cxx/experimental/loop_proto_to_cxx_main.cpp
===
--- /dev/null
+++ tools/clang-fuzzer/proto-to-cxx/experimental/loop_proto_to_cxx_main.cpp
@@ -0,0 +1,34 @@
+//==-- proto_to_cxx_main.cpp - Driver for protobuf-C++ conversion --==//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// Implements a simple driver to print a C++ program from a protobuf.
+//
+//===--===//
+
+// This is a copy and will be updated later to introduce changes
+
+#include 
+#include 
+#include 
+#include 
+
+#include "loop_proto_to_cxx.h"
+
+int main(int argc, char **argv) {
+  for (int i = 1; i < argc; i++) {
+std::fstream in(argv[i]);
+std::string str((std::istreambuf_iterator(in)),
+std::istreambuf_iterator());
+std::cout << "// " << argv[i] << std::endl;
+std::cout << clang_fuzzer::ProtoToCxx(
+reinterpret_cast(str.data()), str.size());
+// std::cout << clang_fuzzer::ProtoStringToCxx(str);
+  }
+}
+
Index: tools/clang-fuzzer/proto-to-cxx/experimental/loop_proto_to_cxx.h
===
--- /dev/null
+++ tools/clang-fuzzer/proto-to-cxx/experimental/loop_proto_to_cxx.h
@@ -0,0 +1,24 @@
+//==-- proto_to_cxx.h - Protobuf-C++ conversion ==//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// Defines functions for converting between protobufs and C++.
+//
+//===--===//
+
+// This is a copy and will be updated later to introduce changes
+
+#include 
+#include 
+#include 
+
+namespace clang_fuzzer {
+class Function;
+std::string FunctionToString(const Function &input);
+std::string ProtoToCxx(const uint8_t *data, size_t size);
+}
Index: tools/clang-fuzzer/proto-to-cxx/experimental/loop_proto_to_cxx.cpp
===
--- /dev/null
+++ tools/clang-fuzzer/proto-to-cxx/experimental/loop_proto_to_cxx.cpp
@@ -0,0 +1,115 @@
+//==-- proto_to_cxx.cpp - Protobuf-C++ conversion --==//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// Implements functions for converting between protobufs and C++.
+//
+//===--===//
+
+// This is a copy and will be updated later to introduce changes
+
+#include "loop_proto_to_cxx.h"
+#include "cxx_loop_proto.pb.h"
+
+// The following is needed to convert protos in human-readable form
+#include 
+
+
+#include 
+#include 
+
+namespace clang_fuzzer {
+
+// Forward decls.
+std::ostream &operator<<(std::ostream &os, const BinaryOp &x);
+std::ostream &operator<<(std::ostream &os, const StatementSeq &x);
+
+// Proto to C++.
+std::ostream &operator<<(std::ostream &os, const Const &x) {
+  return os << "(" << x.val() << ")";
+}
+std::ostream &operator<<(std::ostream &os, const VarRef &x) {
+  return os << "a[" << (static_cast(x.varnum()) % 100) << "]";
+}
+std::ostream &operator<<(std::ostream &os, const Lvalue &x) {
+  return os << x.varref();
+}
+std::ostream &operator<<(std::ostream &os, const Rv

[PATCH] D47666: Refactored clang-fuzzer and added new (copy) files

2018-06-01 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka added a comment.

In https://reviews.llvm.org/D47666#1119821, @vitalybuka wrote:

> Good practice is to avoid merging changes into a single one.
>  Here one patch should be "refactoring" and the second for 
> "loop-proto-fuzzer."


We are doing this for several reasons:

1. smaller patches, faster review
2. easier to investigate regressions caused by smaller patches


Repository:
  rC Clang

https://reviews.llvm.org/D47666



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


[PATCH] D47666: Refactored clang-fuzzer and added new (copy) files

2018-06-01 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka added a comment.

Good practice is to avoid merging changes into a single one.
Here one patch should be "refactoring" and the second for "loop-proto-fuzzer."




Comment at: tools/clang-fuzzer/ExampleClangProtoFuzzer.cpp:29
+/*
 static std::vector CLArgs;
 

Please delete commented code.



Comment at: tools/clang-fuzzer/FuzzerInitialize.h:11
+
+static std::vector CLArgs;
+extern "C" int LLVMFuzzerInitialize(int *argc, char ***argv);

static here means that each module which includes this header is going to have 
own instance of the variable.
I guess you need only one instance in FuzzerInitialize.cpp which can be 
achieved with 
```
extern std::vector CLArgs;

```

However I'd recommend getter:

```
const std::vector& GetCLArgs();
```
with implementation and 
```
static std::vector CLArgs;
```
in FuzzerInitialize.cpp



Comment at: tools/clang-fuzzer/FuzzerInitialize.h:12
+static std::vector CLArgs;
+extern "C" int LLVMFuzzerInitialize(int *argc, char ***argv);
+

you need only CLArgs here.
code which includes this header is not going to call LLVMFuzzerInitialize



Comment at: tools/clang-fuzzer/experimental/ExampleClangLoopProtoFuzzer.cpp:30
 
+/*
 static std::vector CLArgs;

Please remove deleted code


Repository:
  rC Clang

https://reviews.llvm.org/D47666



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


[PATCH] D47666: Refactored clang-fuzzer and added new (copy) files

2018-06-01 Thread Emmett Neyman via Phabricator via cfe-commits
emmettneyman updated this revision to Diff 149585.
emmettneyman added a comment.

- Took out a debug print statement


Repository:
  rC Clang

https://reviews.llvm.org/D47666

Files:
  tools/clang-fuzzer/CMakeLists.txt
  tools/clang-fuzzer/ExampleClangProtoFuzzer.cpp
  tools/clang-fuzzer/FuzzerInitialize.cpp
  tools/clang-fuzzer/FuzzerInitialize.h
  tools/clang-fuzzer/experimental/ExampleClangLoopProtoFuzzer.cpp
  tools/clang-fuzzer/experimental/cxx_loop_proto.proto
  tools/clang-fuzzer/proto-to-cxx/experimental/loop_proto_to_cxx.cpp
  tools/clang-fuzzer/proto-to-cxx/experimental/loop_proto_to_cxx.h
  tools/clang-fuzzer/proto-to-cxx/experimental/loop_proto_to_cxx_main.cpp

Index: tools/clang-fuzzer/proto-to-cxx/experimental/loop_proto_to_cxx_main.cpp
===
--- /dev/null
+++ tools/clang-fuzzer/proto-to-cxx/experimental/loop_proto_to_cxx_main.cpp
@@ -0,0 +1,34 @@
+//==-- proto_to_cxx_main.cpp - Driver for protobuf-C++ conversion --==//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// Implements a simple driver to print a C++ program from a protobuf.
+//
+//===--===//
+
+// This is a copy and will be updated later to introduce changes
+
+#include 
+#include 
+#include 
+#include 
+
+#include "loop_proto_to_cxx.h"
+
+int main(int argc, char **argv) {
+  for (int i = 1; i < argc; i++) {
+std::fstream in(argv[i]);
+std::string str((std::istreambuf_iterator(in)),
+std::istreambuf_iterator());
+std::cout << "// " << argv[i] << std::endl;
+std::cout << clang_fuzzer::ProtoToCxx(
+reinterpret_cast(str.data()), str.size());
+// std::cout << clang_fuzzer::ProtoStringToCxx(str);
+  }
+}
+
Index: tools/clang-fuzzer/proto-to-cxx/experimental/loop_proto_to_cxx.h
===
--- /dev/null
+++ tools/clang-fuzzer/proto-to-cxx/experimental/loop_proto_to_cxx.h
@@ -0,0 +1,24 @@
+//==-- proto_to_cxx.h - Protobuf-C++ conversion ==//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// Defines functions for converting between protobufs and C++.
+//
+//===--===//
+
+// This is a copy and will be updated later to introduce changes
+
+#include 
+#include 
+#include 
+
+namespace clang_fuzzer {
+class Function;
+std::string FunctionToString(const Function &input);
+std::string ProtoToCxx(const uint8_t *data, size_t size);
+}
Index: tools/clang-fuzzer/proto-to-cxx/experimental/loop_proto_to_cxx.cpp
===
--- /dev/null
+++ tools/clang-fuzzer/proto-to-cxx/experimental/loop_proto_to_cxx.cpp
@@ -0,0 +1,115 @@
+//==-- proto_to_cxx.cpp - Protobuf-C++ conversion --==//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// Implements functions for converting between protobufs and C++.
+//
+//===--===//
+
+// This is a copy and will be updated later to introduce changes
+
+#include "loop_proto_to_cxx.h"
+#include "cxx_loop_proto.pb.h"
+
+// The following is needed to convert protos in human-readable form
+#include 
+
+
+#include 
+#include 
+
+namespace clang_fuzzer {
+
+// Forward decls.
+std::ostream &operator<<(std::ostream &os, const BinaryOp &x);
+std::ostream &operator<<(std::ostream &os, const StatementSeq &x);
+
+// Proto to C++.
+std::ostream &operator<<(std::ostream &os, const Const &x) {
+  return os << "(" << x.val() << ")";
+}
+std::ostream &operator<<(std::ostream &os, const VarRef &x) {
+  return os << "a[" << (static_cast(x.varnum()) % 100) << "]";
+}
+std::ostream &operator<<(std::ostream &os, const Lvalue &x) {
+  return os << x.varref();
+}
+std::ostream &operator<<(std::ostream &os, const Rvalue &x) {
+if (x.has_varref()) return os << x.varref();
+if (x.has_cons())   return os << x.cons();
+if (x.has_binop())  return os << x.binop();
+return os << "1";
+}
+std::ostream &operator<<(std::ostream &os, const BinaryOp &x) {
+  os << "(" << x.left();
+  switch (x.op()) {
+case BinaryOp::PLUS: os << "+"; break;
+case BinaryOp::MINUS: os << "-"; break;
+case BinaryOp:

[PATCH] D47666: Refactored clang-fuzzer and added new (copy) files

2018-06-01 Thread Emmett Neyman via Phabricator via cfe-commits
emmettneyman created this revision.
emmettneyman added reviewers: vitalybuka, kcc, morehouse.
Herald added subscribers: cfe-commits, mgorny.

Refactored LLVMFuzzerInitialize function into its own file.
Copied and renamed some files in preparation for new loop-proto-fuzzer.


Repository:
  rC Clang

https://reviews.llvm.org/D47666

Files:
  tools/clang-fuzzer/CMakeLists.txt
  tools/clang-fuzzer/ExampleClangProtoFuzzer.cpp
  tools/clang-fuzzer/FuzzerInitialize.cpp
  tools/clang-fuzzer/FuzzerInitialize.h
  tools/clang-fuzzer/experimental/ExampleClangLoopProtoFuzzer.cpp
  tools/clang-fuzzer/experimental/cxx_loop_proto.proto
  tools/clang-fuzzer/proto-to-cxx/experimental/loop_proto_to_cxx.cpp
  tools/clang-fuzzer/proto-to-cxx/experimental/loop_proto_to_cxx.h
  tools/clang-fuzzer/proto-to-cxx/experimental/loop_proto_to_cxx_main.cpp

Index: tools/clang-fuzzer/proto-to-cxx/experimental/loop_proto_to_cxx_main.cpp
===
--- /dev/null
+++ tools/clang-fuzzer/proto-to-cxx/experimental/loop_proto_to_cxx_main.cpp
@@ -0,0 +1,34 @@
+//==-- proto_to_cxx_main.cpp - Driver for protobuf-C++ conversion --==//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// Implements a simple driver to print a C++ program from a protobuf.
+//
+//===--===//
+
+// This is a copy and will be updated later to introduce changes
+
+#include 
+#include 
+#include 
+#include 
+
+#include "loop_proto_to_cxx.h"
+
+int main(int argc, char **argv) {
+  for (int i = 1; i < argc; i++) {
+std::fstream in(argv[i]);
+std::string str((std::istreambuf_iterator(in)),
+std::istreambuf_iterator());
+std::cout << "// " << argv[i] << std::endl;
+std::cout << clang_fuzzer::ProtoToCxx(
+reinterpret_cast(str.data()), str.size());
+// std::cout << clang_fuzzer::ProtoStringToCxx(str);
+  }
+}
+
Index: tools/clang-fuzzer/proto-to-cxx/experimental/loop_proto_to_cxx.h
===
--- /dev/null
+++ tools/clang-fuzzer/proto-to-cxx/experimental/loop_proto_to_cxx.h
@@ -0,0 +1,24 @@
+//==-- proto_to_cxx.h - Protobuf-C++ conversion ==//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// Defines functions for converting between protobufs and C++.
+//
+//===--===//
+
+// This is a copy and will be updated later to introduce changes
+
+#include 
+#include 
+#include 
+
+namespace clang_fuzzer {
+class Function;
+std::string FunctionToString(const Function &input);
+std::string ProtoToCxx(const uint8_t *data, size_t size);
+}
Index: tools/clang-fuzzer/proto-to-cxx/experimental/loop_proto_to_cxx.cpp
===
--- /dev/null
+++ tools/clang-fuzzer/proto-to-cxx/experimental/loop_proto_to_cxx.cpp
@@ -0,0 +1,115 @@
+//==-- proto_to_cxx.cpp - Protobuf-C++ conversion --==//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// Implements functions for converting between protobufs and C++.
+//
+//===--===//
+
+// This is a copy and will be updated later to introduce changes
+
+#include "loop_proto_to_cxx.h"
+#include "cxx_loop_proto.pb.h"
+
+// The following is needed to convert protos in human-readable form
+#include 
+
+
+#include 
+#include 
+
+namespace clang_fuzzer {
+
+// Forward decls.
+std::ostream &operator<<(std::ostream &os, const BinaryOp &x);
+std::ostream &operator<<(std::ostream &os, const StatementSeq &x);
+
+// Proto to C++.
+std::ostream &operator<<(std::ostream &os, const Const &x) {
+  return os << "(" << x.val() << ")";
+}
+std::ostream &operator<<(std::ostream &os, const VarRef &x) {
+  return os << "a[" << (static_cast(x.varnum()) % 100) << "]";
+}
+std::ostream &operator<<(std::ostream &os, const Lvalue &x) {
+  return os << x.varref();
+}
+std::ostream &operator<<(std::ostream &os, const Rvalue &x) {
+if (x.has_varref()) return os << x.varref();
+if (x.has_cons())   return os << x.cons();
+if (x.has_binop())  return os << x.binop();
+return os << "1";
+}
+std::ostream &operator<<(std::ostream &os, const BinaryOp &x)