|
8 | 8 | using namespace Halide;
|
9 | 9 | using namespace Halide::ConciseCasts;
|
10 | 10 | using namespace Halide::Internal;
|
| 11 | +using std::pair; |
11 | 12 | using std::vector;
|
12 | 13 |
|
13 | 14 | // Note that this deliberately uses int16 values everywhere --
|
14 | 15 | // *not* int32 -- because we want to test CSE, not the simplifier's
|
15 | 16 | // overflow behavior, and using int32 can end up with results
|
16 | 17 | // containing signed_integer_overflow(), which is not helpful here.
|
17 |
| -Expr random_expr(FuzzedDataProvider &fdp, int depth, vector<Expr> &exprs) { |
| 18 | +Expr random_expr(FuzzedDataProvider &fdp, int depth, vector<pair<Expr, int>> &exprs) { |
18 | 19 | if (depth <= 0) {
|
19 | 20 | return i16(fdp.ConsumeIntegralInRange<int>(-5, 4));
|
20 | 21 | }
|
21 | 22 | if (!exprs.empty() && fdp.ConsumeBool()) {
|
22 |
| - // Reuse an existing expression |
23 |
| - return pick_value_in_vector(fdp, exprs); |
| 23 | + // Reuse an existing expression that was generated under conditions at |
| 24 | + // least as strict as our current depth limit. |
| 25 | + auto p = pick_value_in_vector(fdp, exprs); |
| 26 | + if (p.second <= depth) { |
| 27 | + return p.first; |
| 28 | + } |
24 | 29 | }
|
25 | 30 | std::function<Expr()> build_next_expr[] = {
|
26 | 31 | [&]() {
|
@@ -67,13 +72,13 @@ Expr random_expr(FuzzedDataProvider &fdp, int depth, vector<Expr> &exprs) {
|
67 | 72 | },
|
68 | 73 | };
|
69 | 74 | Expr next = fdp.PickValueInArray(build_next_expr)();
|
70 |
| - exprs.push_back(next); |
| 75 | + exprs.emplace_back(next, depth); |
71 | 76 | return next;
|
72 | 77 | }
|
73 | 78 |
|
74 | 79 | extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
|
75 | 80 | FuzzedDataProvider fdp(data, size);
|
76 |
| - vector<Expr> exprs; |
| 81 | + vector<pair<Expr, int>> exprs; |
77 | 82 | Expr orig = random_expr(fdp, 5, exprs);
|
78 | 83 |
|
79 | 84 | Expr csed = common_subexpression_elimination(orig);
|
|
0 commit comments