|
20 | 20 | // |
21 | 21 |
|
22 | 22 | /* |
23 | | -memory too |
24 | 23 | high chance for set at start of loop |
25 | 24 | high chance of get of a set local in the scope of that scope |
26 | 25 | high chance of a tee in that case => loop var |
@@ -90,6 +89,7 @@ class TranslateToFuzzReader { |
90 | 89 |
|
91 | 90 | // the memory that we use, a small portion so that we have a good chance of |
92 | 91 | // looking at writes (we also look outside of this region with small probability) |
| 92 | + // this should be a power of 2 |
93 | 93 | static const int USABLE_MEMORY = 32; |
94 | 94 |
|
95 | 95 | // the number of runtime iterations (function calls, loop backbranches) we |
@@ -158,6 +158,13 @@ class TranslateToFuzzReader { |
158 | 158 | wasm.memory.exists = true; |
159 | 159 | // use one page |
160 | 160 | wasm.memory.initial = wasm.memory.max = 1; |
| 161 | + // init some data |
| 162 | + wasm.memory.segments.emplace_back(builder.makeConst(Literal(int32_t(0)))); |
| 163 | + auto num = upTo(USABLE_MEMORY * 2); |
| 164 | + for (size_t i = 0; i < num; i++) { |
| 165 | + auto value = upTo(512); |
| 166 | + wasm.memory.segments[0].data.push_back(value >= 256 ? 0 : (value & 0xff)); |
| 167 | + } |
161 | 168 | } |
162 | 169 |
|
163 | 170 | void setupTable() { |
@@ -509,6 +516,10 @@ class TranslateToFuzzReader { |
509 | 516 | num /= 2; |
510 | 517 | } |
511 | 518 | } |
| 519 | + // not likely to have a block of size 1 |
| 520 | + if (num == 0 && !oneIn(10)) { |
| 521 | + num++; |
| 522 | + } |
512 | 523 | while (num > 0 && !finishedInput) { |
513 | 524 | ret->list.push_back(make(none)); |
514 | 525 | num--; |
@@ -540,7 +551,17 @@ class TranslateToFuzzReader { |
540 | 551 | ret->name = makeLabel(); |
541 | 552 | breakableStack.push_back(ret); |
542 | 553 | hangStack.push_back(ret); |
543 | | - ret->body = makeMaybeBlock(type); |
| 554 | + // either create random content, or do something more targeted |
| 555 | + if (oneIn(2)) { |
| 556 | + ret->body = makeMaybeBlock(type); |
| 557 | + } else { |
| 558 | + // ensure a branch back. also optionally create some loop vars |
| 559 | + std::vector<Expression*> list; |
| 560 | + list.push_back(makeMaybeBlock(none)); // primary contents |
| 561 | + list.push_back(builder.makeBreak(ret->name, nullptr, makeCondition())); // possible branch back |
| 562 | + list.push_back(make(type)); // final element, so we have the right type |
| 563 | + ret->body = builder.makeBlock(list); |
| 564 | + } |
544 | 565 | breakableStack.pop_back(); |
545 | 566 | hangStack.pop_back(); |
546 | 567 | if (HANG_LIMIT > 0) { |
@@ -1147,6 +1168,12 @@ class TranslateToFuzzReader { |
1147 | 1168 | return upTo(x) == 0; |
1148 | 1169 | } |
1149 | 1170 |
|
| 1171 | + bool onceEvery(Index x) { |
| 1172 | + static int counter = 0; |
| 1173 | + counter++; |
| 1174 | + return counter % x == 0; |
| 1175 | + } |
| 1176 | + |
1150 | 1177 | // apply upTo twice, generating a skewed distribution towards |
1151 | 1178 | // low values |
1152 | 1179 | Index upToSquared(Index x) { |
|
0 commit comments