diff options
-rw-r--r-- | src/wasm/wasm-binary.cpp | 3 | ||||
-rw-r--r-- | src/wasm/wasm-validator.cpp | 8 | ||||
-rw-r--r-- | test/lit/parse-named-memory.wast | 14 |
3 files changed, 20 insertions, 5 deletions
diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp index 54c904459..d023a56c6 100644 --- a/src/wasm/wasm-binary.cpp +++ b/src/wasm/wasm-binary.cpp @@ -3126,8 +3126,7 @@ void WasmBinaryBuilder::readDataSegments() { if (flags & BinaryConsts::HasIndex) { memIdx = getU32LEB(); } - auto* memory = getMemory(memIdx); - curr->memory = memory->name; + memoryRefs[memIdx].push_back(&curr->memory); if (!curr->isPassive) { curr->offset = readExpression(); } diff --git a/src/wasm/wasm-validator.cpp b/src/wasm/wasm-validator.cpp index 44ecbe9c9..cb3841197 100644 --- a/src/wasm/wasm-validator.cpp +++ b/src/wasm/wasm-validator.cpp @@ -3208,9 +3208,11 @@ static void validateDataSegments(Module& module, ValidationInfo& info) { "passive segment should not have an offset"); } else { auto memory = module.getMemoryOrNull(segment->memory); - info.shouldBeTrue(memory != nullptr, - "segment", - "active segment must have a valid memory name"); + if (!info.shouldBeTrue(memory != nullptr, + "segment", + "active segment must have a valid memory name")) { + continue; + } if (memory->is64()) { if (!info.shouldBeEqual(segment->offset->type, Type(Type::i64), diff --git a/test/lit/parse-named-memory.wast b/test/lit/parse-named-memory.wast new file mode 100644 index 000000000..3573376a6 --- /dev/null +++ b/test/lit/parse-named-memory.wast @@ -0,0 +1,14 @@ +;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited. + +;; Regression test for a binary parser bug in which memory names on data +;; segments were not properly updated to use memory names from the name section. + +;; RUN: wasm-as %s -g -o %t.wasm +;; RUN: wasm-opt %t.wasm -S -o - | filecheck %s + +(module + ;; CHECK: (memory $mem0 100) + (memory $mem0 100) + (data (offset (i32.const 0)) "") +) +;; CHECK: (data (i32.const 0) "") |