diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/passes/Memory64Lowering.cpp | 5 | ||||
-rw-r--r-- | src/passes/MemoryPacking.cpp | 11 | ||||
-rw-r--r-- | src/wasm-interpreter.h | 2 | ||||
-rw-r--r-- | src/wasm/wasm-binary.cpp | 2 | ||||
-rw-r--r-- | src/wasm/wasm-emscripten.cpp | 12 | ||||
-rw-r--r-- | src/wasm/wasm-s-parser.cpp | 16 | ||||
-rw-r--r-- | src/wasm/wasm-validator.cpp | 25 |
7 files changed, 51 insertions, 22 deletions
diff --git a/src/passes/Memory64Lowering.cpp b/src/passes/Memory64Lowering.cpp index cee174b63..5e1004797 100644 --- a/src/passes/Memory64Lowering.cpp +++ b/src/passes/Memory64Lowering.cpp @@ -91,6 +91,11 @@ struct Memory64Lowering : public WalkerPass<PostWalker<Memory64Lowering>> { } void visitMemory(Memory* memory) { + for (auto& segment : memory->segments) { + auto* c = segment.offset->cast<Const>(); + c->value = Literal(static_cast<uint32_t>(c->value.geti64())); + c->type = Type::i32; + } // This is visited last. memory->indexType = Type::i32; } diff --git a/src/passes/MemoryPacking.cpp b/src/passes/MemoryPacking.cpp index 7848118b8..b5d317f67 100644 --- a/src/passes/MemoryPacking.cpp +++ b/src/passes/MemoryPacking.cpp @@ -228,7 +228,7 @@ bool MemoryPacking::canOptimize(const Memory& memory, } // Note the maximum address so far. maxAddress = std::max( - maxAddress, Address(c->value.getInteger() + segment.data.size())); + maxAddress, Address(c->value.getUnsigned() + segment.data.size())); } } // All active segments have constant offsets, known at this time, so we may be @@ -239,7 +239,7 @@ bool MemoryPacking::canOptimize(const Memory& memory, for (auto& segment : segments) { if (!segment.isPassive) { auto* c = segment.offset->cast<Const>(); - Address start = c->value.getInteger(); + Address start = c->value.getUnsigned(); DisjointSpans::Span span{start, start + segment.data.size()}; if (space.addAndCheckOverlap(span)) { std::cerr << "warning: active memory segments have overlap, which " @@ -523,7 +523,12 @@ void MemoryPacking::createSplitSegments(Builder& builder, Expression* offset = nullptr; if (!segment.isPassive) { if (auto* c = segment.offset->dynCast<Const>()) { - offset = builder.makeConst(int32_t(c->value.geti32() + range.start)); + if (c->value.type == Type::i32) { + offset = builder.makeConst(int32_t(c->value.geti32() + range.start)); + } else { + assert(c->value.type == Type::i64); + offset = builder.makeConst(int64_t(c->value.geti64() + range.start)); + } } else { assert(ranges.size() == 1); offset = segment.offset; diff --git a/src/wasm-interpreter.h b/src/wasm-interpreter.h index b9a89c643..5032b7277 100644 --- a/src/wasm-interpreter.h +++ b/src/wasm-interpreter.h @@ -3054,7 +3054,7 @@ private: Flow ret; try { ret = this->visit(catchBody); - } catch (const WasmException& e) { + } catch (const WasmException&) { exceptionStack.pop_back(); throw; } diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp index 0f5a03117..ebc5888a0 100644 --- a/src/wasm/wasm-binary.cpp +++ b/src/wasm/wasm-binary.cpp @@ -1354,7 +1354,7 @@ WasmBinaryBuilder::getByteView(size_t size) { throwError("unexpected end of input"); } pos += size; - return {&input[pos - size], &input[pos]}; + return {input.data() + (pos - size), input.data() + pos}; } uint8_t WasmBinaryBuilder::getInt8() { diff --git a/src/wasm/wasm-emscripten.cpp b/src/wasm/wasm-emscripten.cpp index 50b4e9b8f..339214f43 100644 --- a/src/wasm/wasm-emscripten.cpp +++ b/src/wasm/wasm-emscripten.cpp @@ -168,7 +168,7 @@ private: segmentOffsets.push_back(UNKNOWN_OFFSET); } } else if (auto* addrConst = segment.offset->dynCast<Const>()) { - auto address = addrConst->value.geti32(); + auto address = addrConst->value.getUnsigned(); segmentOffsets.push_back(address); } else { // TODO(sbc): Wasm shared libraries have data segments with non-const @@ -285,7 +285,7 @@ void AsmConstWalker::visitCall(Call* curr) { } auto* value = arg->cast<Const>(); - Address address = value->value.getInteger(); + Address address = value->value.getUnsigned(); asmConsts.push_back({address, stringTracker.stringAtAddr(address)}); } @@ -341,7 +341,7 @@ static void removeSegment(Module& wasm, Index segment) { static Address getExportedAddress(Module& wasm, Export* export_) { Global* g = wasm.getGlobal(export_->value); auto* addrConst = g->init->dynCast<Const>(); - return addrConst->value.getInteger(); + return addrConst->value.getUnsigned(); } static std::vector<AsmConst> findEmAsmConsts(Module& wasm, @@ -413,11 +413,11 @@ struct EmJsWalker : public PostWalker<EmJsWalker> { return; } - int64_t address; + Address address; if (curr->kind == ExternalKind::Global) { auto* global = wasm.getGlobal(curr->value); Const* const_ = global->init->cast<Const>(); - address = const_->value.getInteger(); + address = const_->value.getUnsigned(); } else if (curr->kind == ExternalKind::Function) { auto* func = wasm.getFunction(curr->value); // An EM_JS has a single const in the body. Typically it is just returned, @@ -429,7 +429,7 @@ struct EmJsWalker : public PostWalker<EmJsWalker> { << curr->name; } auto* addrConst = consts.list[0]; - address = addrConst->value.getInteger(); + address = addrConst->value.getUnsigned(); } else { return; } diff --git a/src/wasm/wasm-s-parser.cpp b/src/wasm/wasm-s-parser.cpp index 169470181..339d3a04e 100644 --- a/src/wasm/wasm-s-parser.cpp +++ b/src/wasm/wasm-s-parser.cpp @@ -2615,7 +2615,12 @@ void SExpressionWasmBuilder::parseMemory(Element& s, bool preParseImport) { } // (memory (data ..)) format auto j = parseMemoryIndex(inner, 1); - auto offset = allocator.alloc<Const>()->set(Literal(int32_t(0))); + auto offset = allocator.alloc<Const>(); + if (wasm.memory.is64()) { + offset->set(Literal(int64_t(0))); + } else { + offset->set(Literal(int32_t(0))); + } parseInnerData(inner, j, {}, offset, false); wasm.memory.initial = wasm.memory.segments[0].data.size(); return; @@ -2641,8 +2646,13 @@ void SExpressionWasmBuilder::parseMemory(Element& s, bool preParseImport) { } const char* input = curr[j]->c_str(); auto* offset = allocator.alloc<Const>(); - offset->type = Type::i32; - offset->value = Literal(int32_t(offsetValue)); + if (wasm.memory.is64()) { + offset->type = Type::i64; + offset->value = Literal(offsetValue); + } else { + offset->type = Type::i32; + offset->value = Literal(int32_t(offsetValue)); + } if (auto size = strlen(input)) { std::vector<char> data; stringToBinary(input, size, data); diff --git a/src/wasm/wasm-validator.cpp b/src/wasm/wasm-validator.cpp index 6bcdb0e7c..7e9c30c77 100644 --- a/src/wasm/wasm-validator.cpp +++ b/src/wasm/wasm-validator.cpp @@ -2818,7 +2818,7 @@ static void validateMemory(Module& module, ValidationInfo& info) { "memory is shared, but atomics are disabled"); } for (auto& segment : curr.segments) { - Index size = segment.data.size(); + auto size = segment.data.size(); if (segment.isPassive) { info.shouldBeTrue(module.features.hasBulkMemory(), segment.offset, @@ -2828,11 +2828,20 @@ static void validateMemory(Module& module, ValidationInfo& info) { segment.offset, "passive segment should not have an offset"); } else { - if (!info.shouldBeEqual(segment.offset->type, - Type(Type::i32), - segment.offset, - "segment offset should be i32")) { - continue; + if (curr.is64()) { + if (!info.shouldBeEqual(segment.offset->type, + Type(Type::i64), + segment.offset, + "segment offset should be i64")) { + continue; + } + } else { + if (!info.shouldBeEqual(segment.offset->type, + Type(Type::i32), + segment.offset, + "segment offset should be i32")) { + continue; + } } info.shouldBeTrue(checkSegmentOffset(segment.offset, segment.data.size(), @@ -2840,8 +2849,8 @@ static void validateMemory(Module& module, ValidationInfo& info) { segment.offset, "memory segment offset should be reasonable"); if (segment.offset->is<Const>()) { - Index start = segment.offset->cast<Const>()->value.geti32(); - Index end = start + size; + auto start = segment.offset->cast<Const>()->value.getUnsigned(); + auto end = start + size; info.shouldBeTrue(end <= curr.initial * Memory::kPageSize, segment.data.size(), "segment size should fit in memory (end)"); |