[PATCH] D47843: Introducing single for loop into clang_proto_fuzzer

2018-06-07 Thread Vitaly Buka via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL334216: Introducing single for loop into clang_proto_fuzzer 
(authored by vitalybuka, committed by ).

Repository:
  rL LLVM

https://reviews.llvm.org/D47843

Files:
  cfe/trunk/tools/clang-fuzzer/CMakeLists.txt
  cfe/trunk/tools/clang-fuzzer/ExampleClangLoopProtoFuzzer.cpp
  cfe/trunk/tools/clang-fuzzer/cxx_loop_proto.proto
  cfe/trunk/tools/clang-fuzzer/proto-to-cxx/CMakeLists.txt
  cfe/trunk/tools/clang-fuzzer/proto-to-cxx/loop_proto_to_cxx.cpp
  cfe/trunk/tools/clang-fuzzer/proto-to-cxx/loop_proto_to_cxx_main.cpp
  cfe/trunk/tools/clang-fuzzer/proto-to-cxx/proto_to_cxx.h

Index: cfe/trunk/tools/clang-fuzzer/ExampleClangLoopProtoFuzzer.cpp
===
--- cfe/trunk/tools/clang-fuzzer/ExampleClangLoopProtoFuzzer.cpp
+++ cfe/trunk/tools/clang-fuzzer/ExampleClangLoopProtoFuzzer.cpp
@@ -0,0 +1,30 @@
+//===-- ExampleClangLoopProtoFuzzer.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 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 differs from
+///  ExampleClangProtoFuzzer in that it uses the new protobuf that includes
+///  C++ code with a single for loop.
+///
+//===--===//
+
+#include "cxx_loop_proto.pb.h"
+#include "fuzzer-initialize/fuzzer_initialize.h"
+#include "handle-cxx/handle_cxx.h"
+#include "proto-to-cxx/proto_to_cxx.h"
+#include "src/libfuzzer/libfuzzer_macro.h"
+
+using namespace clang_fuzzer;
+
+DEFINE_BINARY_PROTO_FUZZER(const LoopFunction ) {
+  auto S = LoopFunctionToString(input);
+  HandleCXX(S, GetCLArgs());
+}
Index: cfe/trunk/tools/clang-fuzzer/proto-to-cxx/proto_to_cxx.h
===
--- cfe/trunk/tools/clang-fuzzer/proto-to-cxx/proto_to_cxx.h
+++ cfe/trunk/tools/clang-fuzzer/proto-to-cxx/proto_to_cxx.h
@@ -17,6 +17,10 @@
 
 namespace clang_fuzzer {
 class Function;
+class LoopFunction;
+
 std::string FunctionToString(const Function );
 std::string ProtoToCxx(const uint8_t *data, size_t size);
+std::string LoopFunctionToString(const LoopFunction );
+std::string LoopProtoToCxx(const uint8_t *data, size_t size);
 }
Index: cfe/trunk/tools/clang-fuzzer/proto-to-cxx/CMakeLists.txt
===
--- cfe/trunk/tools/clang-fuzzer/proto-to-cxx/CMakeLists.txt
+++ cfe/trunk/tools/clang-fuzzer/proto-to-cxx/CMakeLists.txt
@@ -2,12 +2,21 @@
 set(CMAKE_CXX_FLAGS ${CXX_FLAGS_NOFUZZ})
 
 # Needed by LLVM's CMake checks because this file defines multiple targets.
-set(LLVM_OPTIONAL_SOURCES proto_to_cxx.cpp proto_to_cxx_main.cpp)
+set(LLVM_OPTIONAL_SOURCES proto_to_cxx.cpp proto_to_cxx_main.cpp
+  loop_proto_to_cxx.cpp loop_proto_to_cxx_main.cpp)
 
 add_clang_library(clangProtoToCXX proto_to_cxx.cpp
   DEPENDS clangCXXProto
   LINK_LIBS clangCXXProto ${PROTOBUF_LIBRARIES}
   )
 
+add_clang_library(clangLoopProtoToCXX loop_proto_to_cxx.cpp
+  DEPENDS clangCXXLoopProto
+  LINK_LIBS clangCXXLoopProto ${PROTOBUF_LIBRARIES}
+  )
+
 add_clang_executable(clang-proto-to-cxx proto_to_cxx_main.cpp)
+add_clang_executable(clang-loop-proto-to-cxx loop_proto_to_cxx_main.cpp)
+
 target_link_libraries(clang-proto-to-cxx PRIVATE clangProtoToCXX)
+target_link_libraries(clang-loop-proto-to-cxx PRIVATE clangLoopProtoToCXX)
Index: cfe/trunk/tools/clang-fuzzer/proto-to-cxx/loop_proto_to_cxx_main.cpp
===
--- cfe/trunk/tools/clang-fuzzer/proto-to-cxx/loop_proto_to_cxx_main.cpp
+++ cfe/trunk/tools/clang-fuzzer/proto-to-cxx/loop_proto_to_cxx_main.cpp
@@ -0,0 +1,32 @@
+//==-- loop_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 with loops.
+//
+//===--===//
+
+// This is a copy and will be updated later to introduce changes
+
+#include 
+#include 
+#include 
+#include 
+
+#include "proto_to_cxx.h"
+
+int main(int argc, char **argv) {
+  for (int i = 1; i < argc; i++) {
+

[PATCH] D47843: Introducing single for loop into clang_proto_fuzzer

2018-06-07 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka updated this revision to Diff 150380.
vitalybuka added a comment.

git clang-format -f --style=file HEAD^


Repository:
  rC Clang

https://reviews.llvm.org/D47843

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

Index: tools/clang-fuzzer/proto-to-cxx/proto_to_cxx.h
===
--- tools/clang-fuzzer/proto-to-cxx/proto_to_cxx.h
+++ tools/clang-fuzzer/proto-to-cxx/proto_to_cxx.h
@@ -17,6 +17,10 @@
 
 namespace clang_fuzzer {
 class Function;
+class LoopFunction;
+
 std::string FunctionToString(const Function );
 std::string ProtoToCxx(const uint8_t *data, size_t size);
+std::string LoopFunctionToString(const LoopFunction );
+std::string LoopProtoToCxx(const uint8_t *data, size_t size);
 }
Index: tools/clang-fuzzer/proto-to-cxx/loop_proto_to_cxx_main.cpp
===
--- /dev/null
+++ tools/clang-fuzzer/proto-to-cxx/loop_proto_to_cxx_main.cpp
@@ -0,0 +1,32 @@
+//==-- loop_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 with loops.
+//
+//===--===//
+
+// This is a copy and will be updated later to introduce changes
+
+#include 
+#include 
+#include 
+#include 
+
+#include "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::LoopProtoToCxx(
+reinterpret_cast(str.data()), str.size());
+  }
+}
Index: tools/clang-fuzzer/proto-to-cxx/loop_proto_to_cxx.cpp
===
--- /dev/null
+++ tools/clang-fuzzer/proto-to-cxx/loop_proto_to_cxx.cpp
@@ -0,0 +1,148 @@
+//==-- loop_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++. Extends
+// proto_to_cxx.cpp by wrapping all the generated C++ code in a single for
+// loop. Also coutputs a different function signature that includes a
+// size_t parameter for the loop to use.
+//
+//===--===//
+
+#include "cxx_loop_proto.pb.h"
+#include "proto_to_cxx.h"
+
+// The following is needed to convert protos in human-readable form
+#include 
+
+#include 
+#include 
+
+namespace clang_fuzzer {
+
+// Forward decls.
+std::ostream <<(std::ostream , const BinaryOp );
+std::ostream <<(std::ostream , const StatementSeq );
+
+// Proto to C++.
+std::ostream <<(std::ostream , const Const ) {
+  return os << "(" << x.val() << ")";
+}
+std::ostream <<(std::ostream , const VarRef ) {
+  if (x.is_loop_var()) {
+return os << "a[loop_ctr]";
+  } else {
+return os << "a[" << static_cast(x.varnum()) << " % s]";
+  }
+}
+std::ostream <<(std::ostream , const Lvalue ) {
+  return os << x.varref();
+}
+std::ostream <<(std::ostream , const Rvalue ) {
+  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 <<(std::ostream , const BinaryOp ) {
+  os << "(" << x.left();
+  switch (x.op()) {
+  case BinaryOp::PLUS:
+os << "+";
+break;
+  case BinaryOp::MINUS:
+os << "-";
+break;
+  case BinaryOp::MUL:
+os << "*";
+break;
+  case BinaryOp::DIV:
+os << "/";
+break;
+  case BinaryOp::MOD:
+os << "%";
+break;
+  case BinaryOp::XOR:
+os << "^";
+break;
+  case BinaryOp::AND:
+os << "&";
+break;
+  case BinaryOp::OR:
+os << "|";
+break;
+  case BinaryOp::EQ:
+os << "==";
+break;
+  case BinaryOp::NE:
+os << "!=";
+break;
+  case BinaryOp::LE:
+os << "<=";
+break;
+  case BinaryOp::GE:
+os << ">=";
+break;
+  case BinaryOp::LT:
+os << "<";
+break;
+  case BinaryOp::GT:
+os << ">";
+break;
+  }
+  

[PATCH] D47843: Introducing single for loop into clang_proto_fuzzer

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

- refactored cmake and deleted header file


Repository:
  rC Clang

https://reviews.llvm.org/D47843

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

Index: tools/clang-fuzzer/proto-to-cxx/proto_to_cxx.h
===
--- tools/clang-fuzzer/proto-to-cxx/proto_to_cxx.h
+++ tools/clang-fuzzer/proto-to-cxx/proto_to_cxx.h
@@ -17,6 +17,10 @@
 
 namespace clang_fuzzer {
 class Function;
+class LoopFunction;
+
 std::string FunctionToString(const Function );
 std::string ProtoToCxx(const uint8_t *data, size_t size);
+std::string LoopFunctionToString(const LoopFunction );
+std::string LoopProtoToCxx(const uint8_t *data, size_t size);
 }
Index: tools/clang-fuzzer/proto-to-cxx/loop_proto_to_cxx_main.cpp
===
--- /dev/null
+++ tools/clang-fuzzer/proto-to-cxx/loop_proto_to_cxx_main.cpp
@@ -0,0 +1,33 @@
+//==-- loop_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 with loops.
+//
+//===--===//
+
+// This is a copy and will be updated later to introduce changes
+
+#include 
+#include 
+#include 
+#include 
+
+#include "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::LoopProtoToCxx(
+reinterpret_cast(str.data()), str.size());
+  }
+}
+
Index: tools/clang-fuzzer/proto-to-cxx/loop_proto_to_cxx.cpp
===
--- /dev/null
+++ tools/clang-fuzzer/proto-to-cxx/loop_proto_to_cxx.cpp
@@ -0,0 +1,115 @@
+//==-- loop_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++. Extends
+// proto_to_cxx.cpp by wrapping all the generated C++ code in a single for
+// loop. Also coutputs a different function signature that includes a 
+// size_t parameter for the loop to use.
+//
+//===--===//
+
+#include "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 <<(std::ostream , const BinaryOp );
+std::ostream <<(std::ostream , const StatementSeq );
+
+// Proto to C++.
+std::ostream <<(std::ostream , const Const ) {
+  return os << "(" << x.val() << ")";
+}
+std::ostream <<(std::ostream , const VarRef ) {
+  if (x.is_loop_var()) {
+return os << "a[loop_ctr]";
+  } else {
+return os << "a[" << static_cast(x.varnum()) << " % s]";
+  }
+}
+std::ostream <<(std::ostream , const Lvalue ) {
+  return os << x.varref();
+}
+std::ostream <<(std::ostream , const Rvalue ) {
+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 <<(std::ostream , const BinaryOp ) {
+  os << "(" << x.left();
+  switch (x.op()) {
+case BinaryOp::PLUS: os << "+"; break;
+case BinaryOp::MINUS: os << "-"; break;
+case BinaryOp::MUL: os << "*"; break;
+case BinaryOp::DIV: os << "/"; break;
+case BinaryOp::MOD: os << "%"; break;
+case BinaryOp::XOR: os << "^"; break;
+case BinaryOp::AND: os << "&"; break;
+case BinaryOp::OR: os << "|"; break;
+case BinaryOp::EQ: os << "=="; break;
+case BinaryOp::NE: os << "!="; break;
+case BinaryOp::LE: os << "<="; break;
+case BinaryOp::GE: os << ">="; break;
+case BinaryOp::LT: os << "<"; break;
+case BinaryOp::GT: os << ">"; break;
+  }
+  return os << x.right() << ")";
+}
+std::ostream <<(std::ostream , const AssignmentStatement ) {
+  return 

[PATCH] D47843: Introducing single for loop into clang_proto_fuzzer

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



Comment at: tools/clang-fuzzer/CMakeLists.txt:28
   protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS cxx_proto.proto)
+  protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS cxx_loop_proto.proto)
   set(LLVM_OPTIONAL_SOURCES ${LLVM_OPTIONAL_SOURCES} ${PROTO_SRCS})

I think it makes sense to use separate SRCS and HDRS variables for 
cxx_loop_proto.proto.  Otherwise each proto-fuzzer will be compiled with 
//both// protobufs even though each only uses one.



Comment at: tools/clang-fuzzer/CMakeLists.txt:58
   add_clang_subdirectory(fuzzer-initialize)
 
   # Build the protobuf fuzzer

Why is this here twice?



Comment at: tools/clang-fuzzer/CMakeLists.txt:90
+clangLoopProtoToCXX
+)
 endif()

Maybe you can cut down on some LOC here by creating a 
`COMMON_PROTO_FUZZ_LIBRARIES` variable with the dependencies that overlap 
between the proto-fuzzers.



Comment at: tools/clang-fuzzer/proto-to-cxx/loop_proto_to_cxx.h:22
+std::string LoopProtoToCxx(const uint8_t *data, size_t size);
+}

morehouse wrote:
> Instead of making a whole new header for this, can we simply add  
> `LoopProtoToCxx()` and `LoopFunctionToString()` to proto_to_cxx.h?  Then 
> implement them in `loop_proto_to_cxx.cpp`?
Can we remove this file completely?


Repository:
  rC Clang

https://reviews.llvm.org/D47843



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


[PATCH] D47843: Introducing single for loop into clang_proto_fuzzer

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

- Combined two header files into one


Repository:
  rC Clang

https://reviews.llvm.org/D47843

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

Index: tools/clang-fuzzer/proto-to-cxx/loop_proto_to_cxx_main.cpp
===
--- /dev/null
+++ tools/clang-fuzzer/proto-to-cxx/loop_proto_to_cxx_main.cpp
@@ -0,0 +1,33 @@
+//==-- loop_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 with loops.
+//
+//===--===//
+
+// This is a copy and will be updated later to introduce changes
+
+#include 
+#include 
+#include 
+#include 
+
+#include "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::LoopProtoToCxx(
+reinterpret_cast(str.data()), str.size());
+  }
+}
+
Index: tools/clang-fuzzer/proto-to-cxx/proto_to_cxx.h
===
--- tools/clang-fuzzer/proto-to-cxx/proto_to_cxx.h
+++ tools/clang-fuzzer/proto-to-cxx/proto_to_cxx.h
@@ -17,6 +17,10 @@
 
 namespace clang_fuzzer {
 class Function;
+class LoopFunction;
+
 std::string FunctionToString(const Function );
 std::string ProtoToCxx(const uint8_t *data, size_t size);
+std::string LoopFunctionToString(const LoopFunction );
+std::string LoopProtoToCxx(const uint8_t *data, size_t size);
 }
Index: tools/clang-fuzzer/proto-to-cxx/loop_proto_to_cxx.h
===
--- tools/clang-fuzzer/proto-to-cxx/loop_proto_to_cxx.h
+++ tools/clang-fuzzer/proto-to-cxx/loop_proto_to_cxx.h
@@ -1,22 +1,20 @@
-//==-- proto_to_cxx.h - Protobuf-C++ conversion ==//
+//==-- loop_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++.
+// Defines functions for converting between protobufs with loops and C++.
 //
 //===--===//
 
 #include 
 #include 
 #include 
 
 namespace clang_fuzzer {
-class Function;
-std::string FunctionToString(const Function );
-std::string ProtoToCxx(const uint8_t *data, size_t size);
+class LoopFunction;
 }
Index: tools/clang-fuzzer/proto-to-cxx/loop_proto_to_cxx.cpp
===
--- /dev/null
+++ tools/clang-fuzzer/proto-to-cxx/loop_proto_to_cxx.cpp
@@ -0,0 +1,115 @@
+//==-- loop_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++. Extends
+// proto_to_cxx.cpp by wrapping all the generated C++ code in a single for
+// loop. Also coutputs a different function signature that includes a 
+// size_t parameter for the loop to use.
+//
+//===--===//
+
+#include "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 <<(std::ostream , const BinaryOp );
+std::ostream <<(std::ostream , const StatementSeq );
+
+// Proto to C++.
+std::ostream <<(std::ostream , const Const ) {
+  return os << "(" << x.val() << ")";
+}
+std::ostream <<(std::ostream , const VarRef ) {
+  if (x.is_loop_var()) {
+return os << "a[loop_ctr]";
+  } else {
+

[PATCH] D47843: Introducing single for loop into clang_proto_fuzzer

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



Comment at: tools/clang-fuzzer/cxx_loop_proto.proto:93
+
+message Function {
+  required StatementSeq statements = 1;

Maybe call this `LoopFunction` to distinguish from the other protobuf.



Comment at: tools/clang-fuzzer/fuzzer-initialize/fuzzer_initialize.cpp:14
+/// the fuzzer with the correct command line arguments. 
 ///
 
//===--===//

Nit:  Try not to introduce whitespace at end of lines.  Depending on your 
configuration, this causes git to complain.



Comment at: tools/clang-fuzzer/proto-to-cxx/loop_proto_to_cxx.cpp:115
+
+} // namespace clang_fuzzer

Right now this file duplicates a lot of code from `proto_to_cxx.cpp`.  But 
assuming this file will continue to diverge from `proto_to_cxx.cpp`, I'm fine 
with the duplication for now.



Comment at: tools/clang-fuzzer/proto-to-cxx/loop_proto_to_cxx.h:22
+std::string LoopProtoToCxx(const uint8_t *data, size_t size);
+}

Instead of making a whole new header for this, can we simply add  
`LoopProtoToCxx()` and `LoopFunctionToString()` to proto_to_cxx.h?  Then 
implement them in `loop_proto_to_cxx.cpp`?


Repository:
  rC Clang

https://reviews.llvm.org/D47843



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


[PATCH] D47843: Introducing single for loop into clang_proto_fuzzer

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

Hopefully rebased correctly.


Repository:
  rC Clang

https://reviews.llvm.org/D47843

Files:
  tools/clang-fuzzer/CMakeLists.txt
  tools/clang-fuzzer/ExampleClangLoopProtoFuzzer.cpp
  tools/clang-fuzzer/cxx_loop_proto.proto
  tools/clang-fuzzer/fuzzer-initialize/fuzzer_initialize.cpp
  tools/clang-fuzzer/proto-to-cxx/CMakeLists.txt
  tools/clang-fuzzer/proto-to-cxx/loop_proto_to_cxx.cpp
  tools/clang-fuzzer/proto-to-cxx/loop_proto_to_cxx.h
  tools/clang-fuzzer/proto-to-cxx/loop_proto_to_cxx_main.cpp

Index: tools/clang-fuzzer/proto-to-cxx/loop_proto_to_cxx_main.cpp
===
--- /dev/null
+++ tools/clang-fuzzer/proto-to-cxx/loop_proto_to_cxx_main.cpp
@@ -0,0 +1,33 @@
+//==-- loop_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 with loops.
+//
+//===--===//
+
+// 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::LoopProtoToCxx(
+reinterpret_cast(str.data()), str.size());
+  }
+}
+
Index: tools/clang-fuzzer/proto-to-cxx/loop_proto_to_cxx.h
===
--- /dev/null
+++ tools/clang-fuzzer/proto-to-cxx/loop_proto_to_cxx.h
@@ -0,0 +1,22 @@
+//==-- loop_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 with loops and C++.
+//
+//===--===//
+
+#include 
+#include 
+#include 
+
+namespace clang_fuzzer {
+class Function;
+std::string FunctionToString(const Function );
+std::string LoopProtoToCxx(const uint8_t *data, size_t size);
+}
Index: tools/clang-fuzzer/proto-to-cxx/loop_proto_to_cxx.cpp
===
--- /dev/null
+++ tools/clang-fuzzer/proto-to-cxx/loop_proto_to_cxx.cpp
@@ -0,0 +1,115 @@
+//==-- loop_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++. Extends
+// proto_to_cxx.cpp by wrapping all the generated C++ code in a single for
+// loop. Also coutputs a different function signature that includes a 
+// size_t parameter for the loop to use.
+//
+//===--===//
+
+#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 <<(std::ostream , const BinaryOp );
+std::ostream <<(std::ostream , const StatementSeq );
+
+// Proto to C++.
+std::ostream <<(std::ostream , const Const ) {
+  return os << "(" << x.val() << ")";
+}
+std::ostream <<(std::ostream , const VarRef ) {
+  if (x.is_loop_var()) {
+return os << "a[loop_ctr]";
+  } else {
+return os << "a[" << static_cast(x.varnum()) << " % s]";
+  }
+}
+std::ostream <<(std::ostream , const Lvalue ) {
+  return os << x.varref();
+}
+std::ostream <<(std::ostream , const Rvalue ) {
+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 <<(std::ostream , const BinaryOp ) {
+  os << "(" << x.left();
+  switch (x.op()) {
+case BinaryOp::PLUS: os << "+"; break;
+case BinaryOp::MINUS: os << "-"; break;
+case BinaryOp::MUL: os << "*"; break;
+case BinaryOp::DIV: os << "/"; break;
+case BinaryOp::MOD: os << "%"; break;
+case BinaryOp::XOR: os << "^"; break;
+

[PATCH] D47843: Introducing single for loop into clang_proto_fuzzer

2018-06-06 Thread Matt Morehouse via Phabricator via cfe-commits
morehouse added a comment.

This contains changes from previous patch.  Please rebase.


Repository:
  rC Clang

https://reviews.llvm.org/D47843



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


[PATCH] D47843: Introducing single for loop into clang_proto_fuzzer

2018-06-06 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/fuzzer-initialize/fuzzer_initialize.cpp:23
+
+namespace clang_fuzzer {
+

I guess you already committed this patch.
Could you please try rebase to upstream, e.g. "git pull -r" and re-upload the 
review



Repository:
  rC Clang

https://reviews.llvm.org/D47843



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


[PATCH] D47843: Introducing single for loop into clang_proto_fuzzer

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

Took out typo'd comment


Repository:
  rC Clang

https://reviews.llvm.org/D47843

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

Index: tools/clang-fuzzer/proto-to-cxx/loop_proto_to_cxx_main.cpp
===
--- /dev/null
+++ tools/clang-fuzzer/proto-to-cxx/loop_proto_to_cxx_main.cpp
@@ -0,0 +1,33 @@
+//==-- loop_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 with loops.
+//
+//===--===//
+
+// 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::LoopProtoToCxx(
+reinterpret_cast(str.data()), str.size());
+  }
+}
+
Index: tools/clang-fuzzer/proto-to-cxx/loop_proto_to_cxx.h
===
--- /dev/null
+++ tools/clang-fuzzer/proto-to-cxx/loop_proto_to_cxx.h
@@ -0,0 +1,22 @@
+//==-- loop_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 with loops and C++.
+//
+//===--===//
+
+#include 
+#include 
+#include 
+
+namespace clang_fuzzer {
+class Function;
+std::string FunctionToString(const Function );
+std::string LoopProtoToCxx(const uint8_t *data, size_t size);
+}
Index: tools/clang-fuzzer/proto-to-cxx/loop_proto_to_cxx.cpp
===
--- /dev/null
+++ tools/clang-fuzzer/proto-to-cxx/loop_proto_to_cxx.cpp
@@ -0,0 +1,115 @@
+//==-- loop_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++. Extends
+// proto_to_cxx.cpp by wrapping all the generated C++ code in a single for
+// loop. Also coutputs a different function signature that includes a 
+// size_t parameter for the loop to use.
+//
+//===--===//
+
+#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 <<(std::ostream , const BinaryOp );
+std::ostream <<(std::ostream , const StatementSeq );
+
+// Proto to C++.
+std::ostream <<(std::ostream , const Const ) {
+  return os << "(" << x.val() << ")";
+}
+std::ostream <<(std::ostream , const VarRef ) {
+  if (x.is_loop_var()) {
+return os << "a[loop_ctr]";
+  } else {
+return os << "a[" << static_cast(x.varnum()) << " % s]";
+  }
+}
+std::ostream <<(std::ostream , const Lvalue ) {
+  return os << x.varref();
+}
+std::ostream <<(std::ostream , const Rvalue ) {
+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 <<(std::ostream , const BinaryOp ) {
+  os << "(" << x.left();
+  switch (x.op()) {
+case BinaryOp::PLUS: os << "+"; break;
+case BinaryOp::MINUS: os << "-"; break;
+case 

[PATCH] D47843: Introducing single for loop into clang_proto_fuzzer

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

Created a new protobuf and protobuf-to-C++ "converter" that wraps the entire 
C++ code in a single for loop.

- Slightly changed cxx_proto.proto -> cxx_loop_proto.proto
- Made some changes to proto_to_cxx files to handle the new kind of protobuf
- Created ExampleClangLoopProtoFuzzer to test new protobuf and "converter"


Repository:
  rC Clang

https://reviews.llvm.org/D47843

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

Index: tools/clang-fuzzer/proto-to-cxx/loop_proto_to_cxx_main.cpp
===
--- /dev/null
+++ tools/clang-fuzzer/proto-to-cxx/loop_proto_to_cxx_main.cpp
@@ -0,0 +1,33 @@
+//==-- loop_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 with loops.
+//
+//===--===//
+
+// 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::LoopProtoToCxx(
+reinterpret_cast(str.data()), str.size());
+  }
+}
+
Index: tools/clang-fuzzer/proto-to-cxx/loop_proto_to_cxx.h
===
--- /dev/null
+++ tools/clang-fuzzer/proto-to-cxx/loop_proto_to_cxx.h
@@ -0,0 +1,22 @@
+//==-- loop_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 with loops and C++.
+//
+//===--===//
+
+#include 
+#include 
+#include 
+
+namespace clang_fuzzer {
+class Function;
+std::string FunctionToString(const Function );
+std::string LoopProtoToCxx(const uint8_t *data, size_t size);
+}
Index: tools/clang-fuzzer/proto-to-cxx/proto_to_cxx.cpp
===
--- tools/clang-fuzzer/proto-to-cxx/proto_to_cxx.cpp
+++ tools/clang-fuzzer/proto-to-cxx/proto_to_cxx.cpp
@@ -1,3 +1,4 @@
+//M
 //==-- proto_to_cxx.cpp - Protobuf-C++ conversion --==//
 //
 // The LLVM Compiler Infrastructure
Index: tools/clang-fuzzer/proto-to-cxx/loop_proto_to_cxx.cpp
===
--- tools/clang-fuzzer/proto-to-cxx/loop_proto_to_cxx.cpp
+++ tools/clang-fuzzer/proto-to-cxx/loop_proto_to_cxx.cpp
@@ -1,18 +1,25 @@
-//==-- proto_to_cxx.cpp - Protobuf-C++ conversion --==//
+//==-- loop_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++.
+// Implements functions for converting between protobufs and C++. Extends
+// proto_to_cxx.cpp by wrapping all the generated C++ code in a single for
+// loop. Also coutputs a different function signature that includes a 
+// size_t parameter for the loop to use.
 //
 //===--===//
 
-#include "proto_to_cxx.h"
-#include "cxx_proto.pb.h"
+#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 
@@ -28,7 +35,11 @@
   return os << "(" << x.val() << ")";
 }
 std::ostream <<(std::ostream , const VarRef ) {
-  return os << "a[" <<