diff options
-rw-r--r-- | src/ir/memory-utils.cpp | 9 | ||||
-rw-r--r-- | src/tools/wasm-ctor-eval.cpp | 8 | ||||
-rw-r--r-- | test/lit/ctor-eval/memory64.wast | 42 |
3 files changed, 54 insertions, 5 deletions
diff --git a/src/ir/memory-utils.cpp b/src/ir/memory-utils.cpp index 0f6b77602..552e4ff9a 100644 --- a/src/ir/memory-utils.cpp +++ b/src/ir/memory-utils.cpp @@ -21,8 +21,12 @@ namespace wasm::MemoryUtils { bool flatten(Module& wasm) { + // If there are no memories then they are already flat, in the empty sense. + if (wasm.memories.empty()) { + return true; + } // Flatten does not currently have support for multimemory - if (wasm.memories.size() > 1) { + if (wasm.memories.size() != 1) { return false; } // The presence of any instruction that cares about segment identity is a @@ -105,7 +109,8 @@ bool flatten(Module& wasm) { } std::copy(segment->data.begin(), segment->data.end(), data.begin() + start); } - dataSegments[0]->offset->cast<Const>()->value = Literal(int32_t(0)); + dataSegments[0]->offset->cast<Const>()->value = + Literal::makeFromInt32(0, wasm.memories[0]->indexType); dataSegments[0]->data.swap(data); wasm.removeDataSegments( [&](DataSegment* curr) { return curr->name != dataSegments[0]->name; }); diff --git a/src/tools/wasm-ctor-eval.cpp b/src/tools/wasm-ctor-eval.cpp index 72ad459d3..499c1bf6c 100644 --- a/src/tools/wasm-ctor-eval.cpp +++ b/src/tools/wasm-ctor-eval.cpp @@ -508,12 +508,14 @@ private: void applyMemoryToModule() { // Memory must have already been flattened into the standard form: one // segment at offset 0, or none. + auto& memory = wasm->memories[0]; if (wasm->dataSegments.empty()) { Builder builder(*wasm); auto curr = builder.makeDataSegment(); - curr->offset = builder.makeConst(int32_t(0)); + curr->offset = + builder.makeConst(Literal::makeFromInt32(0, memory->indexType)); curr->setName(Name::fromInt(0), false); - curr->memory = wasm->memories[0]->name; + curr->memory = memory->name; wasm->addDataSegment(std::move(curr)); } auto& segment = wasm->dataSegments[0]; @@ -521,7 +523,7 @@ private: // Copy the current memory contents after execution into the Module's // memory. - segment->data = memories[wasm->memories[0]->name]; + segment->data = memories[memory->name]; } // Serializing GC data requires more work than linear memory, because diff --git a/test/lit/ctor-eval/memory64.wast b/test/lit/ctor-eval/memory64.wast new file mode 100644 index 000000000..b1e7b1613 --- /dev/null +++ b/test/lit/ctor-eval/memory64.wast @@ -0,0 +1,42 @@ +;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited. +;; RUN: wasm-ctor-eval %s --ctors=mem,tab --kept-exports=mem,tab --quiet -all -S -o - | filecheck %s + +(module + (memory $0 i64 16 17 shared) + (data $0 (i64.const 0) "abcd") + + (table i64 1 funcref) + (elem $foo) + + (func $mem (export "mem") (result i32) + (i32.load + (i64.const 0) + ) + ) + + ;; CHECK: (type $0 (func (result funcref))) + + ;; CHECK: (type $1 (func (result i32))) + + ;; CHECK: (table $0 i64 1 funcref) + + ;; CHECK: (export "mem" (func $mem_2)) + + ;; CHECK: (export "tab" (func $tab)) + + ;; CHECK: (func $tab (type $0) (result funcref) + ;; CHECK-NEXT: (table.get $0 + ;; CHECK-NEXT: (i64.const 0) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + (func $tab (export "tab") (result funcref) + ;; Not optimized yet, but we should not error either. + (table.get + (i64.const 0) + ) + ) +) + +;; CHECK: (func $mem_2 (type $1) (result i32) +;; CHECK-NEXT: (i32.const 1684234849) +;; CHECK-NEXT: ) |