summaryrefslogtreecommitdiff
path: root/src/wasm/wasm-binary.cpp
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2022-08-18 09:48:18 -0700
committerGitHub <noreply@github.com>2022-08-18 09:48:18 -0700
commit296a63eaaabd28990d6b3acf63af3d9d21190b8d (patch)
tree430536ca67dddc0550faaf19f3948f0039fc7b24 /src/wasm/wasm-binary.cpp
parent68bf5e3790c8ca95f52c5c5758775a592e708d77 (diff)
downloadbinaryen-296a63eaaabd28990d6b3acf63af3d9d21190b8d.tar.gz
binaryen-296a63eaaabd28990d6b3acf63af3d9d21190b8d.tar.bz2
binaryen-296a63eaaabd28990d6b3acf63af3d9d21190b8d.zip
Fix Memory64 binary parsing after #4811 (#4933)
Due to missing test coverage, we missed in #4811 that some memory operations needed to get make64() called on them.
Diffstat (limited to 'src/wasm/wasm-binary.cpp')
-rw-r--r--src/wasm/wasm-binary.cpp36
1 files changed, 21 insertions, 15 deletions
diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp
index fe827f291..87fb0e293 100644
--- a/src/wasm/wasm-binary.cpp
+++ b/src/wasm/wasm-binary.cpp
@@ -2220,6 +2220,16 @@ Name WasmBinaryBuilder::getTagName(Index index) {
return wasm.tags[index]->name;
}
+Memory* WasmBinaryBuilder::getMemory(Index index) {
+ Index numMemoryImports = memoryImports.size();
+ if (index < numMemoryImports) {
+ return memoryImports[index];
+ } else if (index - numMemoryImports < memories.size()) {
+ return memories[index - numMemoryImports].get();
+ }
+ throwError("Memory index out of range.");
+}
+
void WasmBinaryBuilder::getResizableLimits(Address& initial,
Address& max,
bool& shared,
@@ -3047,16 +3057,7 @@ void WasmBinaryBuilder::readDataSegments() {
if (flags & BinaryConsts::HasIndex) {
memIdx = getU32LEB();
}
- Memory* memory = nullptr;
- Index numMemoryImports = memoryImports.size();
- if (memIdx < numMemoryImports) {
- memory = memoryImports[memIdx];
- } else if (memIdx - numMemoryImports < memories.size()) {
- memory = memories[memIdx - numMemoryImports].get();
- }
- if (!memory) {
- throwError("Memory index out of range while reading data segments.");
- }
+ auto* memory = getMemory(memIdx);
curr->memory = memory->name;
if (!curr->isPassive) {
curr->offset = readExpression();
@@ -6515,17 +6516,22 @@ void WasmBinaryBuilder::visitReturn(Return* curr) {
void WasmBinaryBuilder::visitMemorySize(MemorySize* curr) {
BYN_TRACE("zz node: MemorySize\n");
- Index memIdx = getU32LEB();
+ Index index = getU32LEB();
+ if (getMemory(index)->is64()) {
+ curr->make64();
+ }
curr->finalize();
- memoryRefs[memIdx].push_back(&curr->memory);
+ memoryRefs[index].push_back(&curr->memory);
}
void WasmBinaryBuilder::visitMemoryGrow(MemoryGrow* curr) {
BYN_TRACE("zz node: MemoryGrow\n");
curr->delta = popNonVoidExpression();
- Index memIdx = getU32LEB();
- curr->finalize();
- memoryRefs[memIdx].push_back(&curr->memory);
+ Index index = getU32LEB();
+ if (getMemory(index)->is64()) {
+ curr->make64();
+ }
+ memoryRefs[index].push_back(&curr->memory);
}
void WasmBinaryBuilder::visitNop(Nop* curr) { BYN_TRACE("zz node: Nop\n"); }