summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/ir/module-utils.cpp1
-rw-r--r--src/tools/fuzzing/fuzzing.cpp22
-rw-r--r--test/lit/merge/table64.wat19
-rw-r--r--test/lit/merge/table64.wat.second12
-rw-r--r--test/passes/fuzz_metrics_noprint.bin.txt55
-rw-r--r--test/passes/translate-to-fuzz_all-features_metrics_noprint.txt82
6 files changed, 126 insertions, 65 deletions
diff --git a/src/ir/module-utils.cpp b/src/ir/module-utils.cpp
index 2f26cfa77..7aed263a9 100644
--- a/src/ir/module-utils.cpp
+++ b/src/ir/module-utils.cpp
@@ -175,6 +175,7 @@ Table* copyTable(const Table* table, Module& out) {
ret->initial = table->initial;
ret->max = table->max;
+ ret->indexType = table->indexType;
return out.addTable(std::move(ret));
}
diff --git a/src/tools/fuzzing/fuzzing.cpp b/src/tools/fuzzing/fuzzing.cpp
index 26c321961..ed3287a7c 100644
--- a/src/tools/fuzzing/fuzzing.cpp
+++ b/src/tools/fuzzing/fuzzing.cpp
@@ -370,8 +370,26 @@ void TranslateToFuzzReader::setupTables() {
if (iter != wasm.tables.end()) {
table = iter->get();
} else {
- auto tablePtr = builder.makeTable(
- Names::getValidTableName(wasm, "fuzzing_table"), funcref, 0, 0);
+ // Start from a potentially empty table.
+ Address initial = upTo(10);
+ // Make the max potentially higher, or unlimited.
+ Address max;
+ if (oneIn(2)) {
+ max = initial + upTo(4);
+ } else {
+ max = Memory::kUnlimitedSize;
+ }
+ // Fuzz wasm64 when possible, sometimes.
+ auto indexType = Type::i32;
+ if (wasm.features.hasMemory64() && oneIn(2)) {
+ indexType = Type::i64;
+ }
+ auto tablePtr =
+ builder.makeTable(Names::getValidTableName(wasm, "fuzzing_table"),
+ funcref,
+ initial,
+ max,
+ indexType);
tablePtr->hasExplicitName = true;
table = wasm.addTable(std::move(tablePtr));
}
diff --git a/test/lit/merge/table64.wat b/test/lit/merge/table64.wat
new file mode 100644
index 000000000..a313b5bc3
--- /dev/null
+++ b/test/lit/merge/table64.wat
@@ -0,0 +1,19 @@
+;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited.
+
+;; RUN: wasm-merge %s first %s.second second --rename-export-conflicts -all -S -o - | filecheck %s
+
+;; An empty module. The interesting part is in the second module: we should
+;; copy the i64 table properly.
+(module
+)
+;; CHECK: (type $0 (func))
+
+;; CHECK: (table $table i64 15 15 funcref)
+
+;; CHECK: (elem $0 (i64.const 0) $second)
+
+;; CHECK: (export "table" (table $table))
+
+;; CHECK: (func $second (type $0)
+;; CHECK-NEXT: (nop)
+;; CHECK-NEXT: )
diff --git a/test/lit/merge/table64.wat.second b/test/lit/merge/table64.wat.second
new file mode 100644
index 000000000..cbc5a78fb
--- /dev/null
+++ b/test/lit/merge/table64.wat.second
@@ -0,0 +1,12 @@
+;; A module with a wasm64 table. We must copy it properly when we merge.
+(module
+ (table $table i64 15 15 funcref)
+
+ (elem $0 (i64.const 0) $second)
+
+ (export "table" (table $table))
+
+ (func $second)
+)
+
+
diff --git a/test/passes/fuzz_metrics_noprint.bin.txt b/test/passes/fuzz_metrics_noprint.bin.txt
index cf3692a1f..ba0ccaa10 100644
--- a/test/passes/fuzz_metrics_noprint.bin.txt
+++ b/test/passes/fuzz_metrics_noprint.bin.txt
@@ -1,34 +1,35 @@
Metrics
total
- [exports] : 14
- [funcs] : 17
- [globals] : 10
+ [exports] : 25
+ [funcs] : 40
+ [globals] : 18
[imports] : 4
[memories] : 1
[memory-data] : 24
- [table-data] : 3
+ [table-data] : 19
[tables] : 1
[tags] : 0
- [total] : 8422
- [vars] : 42
- Binary : 633
- Block : 1449
- Break : 335
- Call : 123
- CallIndirect : 40
- Const : 1247
- Drop : 85
- GlobalGet : 707
- GlobalSet : 526
- If : 490
- Load : 156
- LocalGet : 627
- LocalSet : 520
- Loop : 235
- Nop : 126
- RefFunc : 3
- Return : 87
- Select : 82
- Store : 70
- Unary : 622
- Unreachable : 259
+ [total] : 5335
+ [vars] : 170
+ Binary : 403
+ Block : 900
+ Break : 163
+ Call : 197
+ CallIndirect : 11
+ Const : 824
+ Drop : 56
+ GlobalGet : 464
+ GlobalSet : 342
+ If : 298
+ Load : 87
+ LocalGet : 402
+ LocalSet : 304
+ Loop : 126
+ Nop : 74
+ RefFunc : 19
+ Return : 60
+ Select : 34
+ Store : 46
+ Switch : 1
+ Unary : 356
+ Unreachable : 168
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 9d2b4e3da..fd37193f5 100644
--- a/test/passes/translate-to-fuzz_all-features_metrics_noprint.txt
+++ b/test/passes/translate-to-fuzz_all-features_metrics_noprint.txt
@@ -1,46 +1,56 @@
Metrics
total
- [exports] : 8
- [funcs] : 9
- [globals] : 26
+ [exports] : 7
+ [funcs] : 8
+ [globals] : 4
[imports] : 8
[memories] : 1
[memory-data] : 112
[table-data] : 0
[tables] : 1
- [tags] : 2
- [total] : 487
- [vars] : 37
- ArrayFill : 1
- ArrayGet : 1
- ArrayLen : 2
- ArrayNew : 7
+ [tags] : 1
+ [total] : 645
+ [vars] : 33
+ ArrayGet : 2
+ ArrayLen : 1
+ ArrayNew : 3
ArrayNewFixed : 5
- Binary : 69
- Block : 42
- Break : 2
- Call : 9
- Const : 103
- Drop : 3
- GlobalGet : 30
- GlobalSet : 20
- If : 13
- Load : 18
- LocalGet : 41
- LocalSet : 24
- Loop : 2
- Nop : 1
- Pop : 1
- RefFunc : 21
- RefNull : 5
+ AtomicCmpxchg : 1
+ AtomicFence : 1
+ AtomicRMW : 1
+ Binary : 76
+ Block : 64
+ Break : 4
+ Call : 15
+ Const : 149
+ DataDrop : 1
+ Drop : 1
+ GlobalGet : 25
+ GlobalSet : 22
+ If : 22
+ Load : 25
+ LocalGet : 55
+ LocalSet : 35
+ Loop : 4
+ MemoryFill : 1
+ Nop : 7
+ Pop : 6
+ RefAs : 5
+ RefCast : 1
+ RefEq : 2
+ RefFunc : 13
+ RefIsNull : 1
+ RefNull : 10
Return : 5
- Select : 2
- StringConst : 3
- StringEq : 1
- StructNew : 27
- Try : 1
+ SIMDExtract : 1
+ Select : 6
+ StringConst : 1
+ StringEncode : 1
+ StructNew : 24
+ StructSet : 1
+ Try : 7
TryTable : 2
- TupleExtract : 1
- TupleMake : 4
- Unary : 11
- Unreachable : 10
+ TupleExtract : 2
+ TupleMake : 3
+ Unary : 23
+ Unreachable : 11