Index: tools/clang-fuzzer/cxx_loop_proto.proto =================================================================== --- tools/clang-fuzzer/cxx_loop_proto.proto +++ tools/clang-fuzzer/cxx_loop_proto.proto @@ -9,10 +9,11 @@ /// /// \file /// This file describes a subset of C++ as a protobuf. It is used to -/// more easily find interesting inputs for fuzzing Clang. This subset -/// differs from the one defined in cxx_proto.proto by eliminating while -/// loops and conditionals. The goal is that the C++ code generated will be -/// more likely to stress the LLVM loop vectorizer. +/// more easily find interesting inputs for fuzzing LLVM's vectorizer. +/// This subset differs from the one defined in cxx_proto.proto by eliminating +/// while loops and conditionals. The goal is that the C++ code generated will +/// be more likely to stress the LLVM loop vectorizer. The code generated will +/// contain either a single loop or two nested loops. /// //===----------------------------------------------------------------------===// @@ -74,7 +75,8 @@ } message LoopFunction { - required StatementSeq statements = 1; + optional StatementSeq inner_statements = 1; + required StatementSeq outer_statements = 2; } package clang_fuzzer; 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 @@ -8,10 +8,10 @@ //===----------------------------------------------------------------------===// // // Implements functions for converting between protobufs and C++. Differs from -// 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. The C++ code generated is meant to -// stress the LLVM loop vectorizer. +// proto_to_cxx.cpp by wrapping all the generated C++ code in either a single +// for loop or two nested loops. Also outputs a different function signature +// that includes a size_t parameter for the loop to use. The C++ code generated +// is meant to stress the LLVM loop vectorizer. // // Still a work in progress. // @@ -28,6 +28,17 @@ namespace clang_fuzzer { +static bool inner_loop = false; +class InnerLoop { + public: + InnerLoop() { + inner_loop = true; + } + ~InnerLoop() { + inner_loop = false; + } +}; + // Forward decls. std::ostream &operator<<(std::ostream &os, const BinaryOp &x); std::ostream &operator<<(std::ostream &os, const StatementSeq &x); @@ -37,13 +48,14 @@ return os << "(" << x.val() << ")"; } std::ostream &operator<<(std::ostream &os, const VarRef &x) { + std::string which_loop = inner_loop ? "j" : "i"; switch (x.arr()) { case VarRef::ARR_A: - return os << "a[i]"; + return os << "a[" << which_loop << "]"; case VarRef::ARR_B: - return os << "b[i]"; + return os << "b[" << which_loop << "]"; case VarRef::ARR_C: - return os << "c[i]"; + return os << "c[" << which_loop << "]"; } } std::ostream &operator<<(std::ostream &os, const Rvalue &x) { @@ -108,10 +120,27 @@ os << st; return os; } +void NestedLoopToString(std::ostream &os, const LoopFunction &x) { + os << "void foo(int *a, int *b, int *__restrict__ c, size_t s) {\n" + << "for (int i=0; i