diff --git a/src/tools/fuzzing.h b/src/tools/fuzzing.h
index 51dbb185cd9..3c47d2ed0d9 100644
--- a/src/tools/fuzzing.h
+++ b/src/tools/fuzzing.h
@@ -531,6 +531,8 @@ class TranslateToFuzzReader {
Expression* makeBulkMemory(Type type);
Expression* makeTableGet(Type type);
Expression* makeTableSet(Type type);
+ Expression* makeTableSize(Type type);
+ Expression* makeTableGrow(Type type);
// TODO: support other RefIs variants, and rename this
Expression* makeRefIsNull(Type type);
Expression* makeRefEq(Type type);
diff --git a/src/tools/fuzzing/fuzzing.cpp b/src/tools/fuzzing/fuzzing.cpp
index eac05d35e50..7c67a3bfb56 100644
--- a/src/tools/fuzzing/fuzzing.cpp
+++ b/src/tools/fuzzing/fuzzing.cpp
@@ -1030,7 +1030,7 @@ void TranslateToFuzzReader::finalizeTable() {
table->initial = std::min(table->initial, ReasonableMaxTableSize);
assert(ReasonableMaxTableSize <= Table::kMaxSize);
- table->max = oneIn(2) ? Address(Table::kUnlimitedSize) : table->initial;
+ table->max = oneIn(2) ? ReasonableMaxTableSize : table->initial;
if (!preserveImportsAndExports) {
// Avoid an imported table (which the fuzz harness would need to handle).
@@ -2919,6 +2919,12 @@ Expression* TranslateToFuzzReader::_makeConcrete(Type type) {
options.add(
FeatureSet::MVP, &Self::makeMemorySize, &Self::makeMemoryGrow);
}
+ if (std::any_of(wasm.tables.begin(), wasm.tables.end(), [&](auto& table) {
+ return table->addressType == type;
+ })) {
+ options.add(
+ FeatureSet::ReferenceTypes, &Self::makeTableSize, &Self::makeTableGrow);
+ }
}
if (type == Type::i32) {
if (callExportCatchImportName || callRefCatchImportName) {
@@ -5724,6 +5730,36 @@ Expression* TranslateToFuzzReader::makeTableSet(Type type) {
}
}
+Expression* TranslateToFuzzReader::makeTableSize(Type type) {
+ std::vector
tables;
+ for (auto& table : wasm.tables) {
+ if (table->addressType == type) {
+ tables.push_back(table.get());
+ }
+ }
+ if (tables.empty()) {
+ return makeTrivial(type);
+ }
+ auto* table = pick(tables);
+ return builder.makeTableSize(table->name);
+}
+
+Expression* TranslateToFuzzReader::makeTableGrow(Type type) {
+ std::vector tables;
+ for (auto& table : wasm.tables) {
+ if (table->addressType == type) {
+ tables.push_back(table.get());
+ }
+ }
+ if (tables.empty()) {
+ return makeTrivial(type);
+ }
+ auto* table = pick(tables);
+ auto* value = make(table->type);
+ auto* delta = make(type);
+ return builder.makeTableGrow(table->name, value, delta);
+}
+
Expression* TranslateToFuzzReader::makeRefIsNull(Type type) {
assert(type == Type::i32);
assert(wasm.features.hasReferenceTypes());
diff --git a/test/passes/translate-to-fuzz_all-features_metrics_noprint.txt b/test/passes/translate-to-fuzz_all-features_metrics_noprint.txt
index a08f74d7a57..d8d1217447b 100644
--- a/test/passes/translate-to-fuzz_all-features_metrics_noprint.txt
+++ b/test/passes/translate-to-fuzz_all-features_metrics_noprint.txt
@@ -1,95 +1,99 @@
Metrics
total
- [exports] : 107
- [funcs] : 214
+ [exports] : 48
+ [funcs] : 109
[globals] : 13
[imports] : 13
[memories] : 1
[memory-data] : 31
- [table-data] : 56
+ [table-data] : 21
[tables] : 2
[tags] : 2
- [total] : 99434
- [vars] : 3971
- ArrayCmpxchg : 19
- ArrayCopy : 36
- ArrayFill : 39
- ArrayGet : 376
- ArrayLen : 507
- ArrayNew : 1221
- ArrayNewFixed : 354
- ArrayRMW : 15
- ArraySet : 60
- AtomicCmpxchg : 33
- AtomicFence : 61
- AtomicNotify : 12
- AtomicRMW : 43
- AtomicWait : 7
- Binary : 3587
- Block : 6879
- BrOn : 635
- Break : 956
- Call : 987
- CallIndirect : 141
- CallRef : 205
- Const : 13411
- ContBind : 2
- ContNew : 114
- DataDrop : 21
- Drop : 889
- ElemDrop : 7
- GlobalGet : 5100
- GlobalSet : 2130
- I31Get : 56
- If : 2386
- Load : 245
- LocalGet : 9715
- LocalSet : 3812
- Loop : 846
- MemoryCopy : 13
- MemoryFill : 20
- MemoryGrow : 38
- MemoryInit : 10
- MemorySize : 32
- Nop : 636
- Pop : 187
- RefAs : 9895
- RefCast : 706
- RefEq : 243
- RefFunc : 1906
- RefGetDesc : 68
- RefI31 : 686
- RefIsNull : 57
- RefNull : 11596
- RefTest : 55
- Return : 346
- SIMDExtract : 119
- SIMDShift : 3
- SIMDShuffle : 2
- SIMDTernary : 6
- Select : 289
- Store : 116
- StringConst : 391
- StringEncode : 63
- StringEq : 56
- StringMeasure : 68
- StringNew : 3
- StringSliceWTF : 2
+ [total] : 97338
+ [vars] : 3397
+ ArrayCmpxchg : 27
+ ArrayCopy : 35
+ ArrayFill : 42
+ ArrayGet : 391
+ ArrayLen : 581
+ ArrayNew : 1137
+ ArrayNewFixed : 340
+ ArrayRMW : 21
+ ArraySet : 79
+ AtomicCmpxchg : 44
+ AtomicFence : 76
+ AtomicNotify : 24
+ AtomicRMW : 37
+ AtomicWait : 13
+ Binary : 3631
+ Block : 6694
+ BrOn : 632
+ Break : 964
+ Call : 649
+ CallIndirect : 130
+ CallRef : 206
+ Const : 12510
+ ContBind : 1
+ ContNew : 110
+ DataDrop : 10
+ Drop : 895
+ ElemDrop : 12
+ GlobalGet : 4805
+ GlobalSet : 1896
+ I31Get : 77
+ If : 2348
+ Load : 307
+ LocalGet : 12016
+ LocalSet : 3847
+ Loop : 834
+ MemoryCopy : 18
+ MemoryFill : 21
+ MemoryGrow : 39
+ MemoryInit : 17
+ MemorySize : 36
+ Nop : 674
+ Pop : 189
+ RefAs : 9740
+ RefCast : 704
+ RefEq : 277
+ RefFunc : 1822
+ RefGetDesc : 53
+ RefI31 : 625
+ RefIsNull : 62
+ RefNull : 9738
+ RefTest : 62
+ Return : 362
+ SIMDExtract : 113
+ SIMDReplace : 2
+ SIMDShift : 1
+ SIMDShuffle : 3
+ SIMDTernary : 2
+ Select : 321
+ Store : 159
+ StringConst : 400
+ StringEncode : 51
+ StringEq : 75
+ StringMeasure : 78
+ StringNew : 4
+ StringSliceWTF : 3
StringWTF16Get : 60
- StructCmpxchg : 38
- StructGet : 449
- StructNew : 11746
- StructRMW : 51
- StructSet : 57
- Switch : 7
- TableSet : 67
- Throw : 89
- ThrowRef : 15
- Try : 365
- TryTable : 430
- TupleExtract : 208
- TupleMake : 231
- Unary : 1980
- Unreachable : 1097
- WideIntAddSub : 11
- WideIntMul : 14
+ StructCmpxchg : 40
+ StructGet : 384
+ StructNew : 11028
+ StructRMW : 49
+ StructSet : 71
+ Switch : 3
+ TableGet : 1
+ TableGrow : 94
+ TableSet : 77
+ TableSize : 107
+ Throw : 114
+ ThrowRef : 6
+ Try : 375
+ TryTable : 478
+ TupleExtract : 205
+ TupleMake : 331
+ Unary : 1834
+ Unreachable : 975
+ WideIntAddSub : 23
+ WideIntMul : 11