Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(140)

Unified Diff: src/compiler/wasm-compiler.cc

Issue 2067433003: [wasm] MemSize, BoundsCheck should use Relocatable constants (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/compiler/wasm-compiler.cc
diff --git a/src/compiler/wasm-compiler.cc b/src/compiler/wasm-compiler.cc
index ae804471b9af05139cbc805c27b3425fb299aec8..fcd330619cf251200d3c7a87d93dd19ab4bf26cc 100644
--- a/src/compiler/wasm-compiler.cc
+++ b/src/compiler/wasm-compiler.cc
@@ -2529,10 +2529,13 @@ Node* WasmGraphBuilder::MemSize(uint32_t offset) {
DCHECK(module_ && module_->instance);
uint32_t size = static_cast<uint32_t>(module_->instance->mem_size);
if (offset == 0) {
- if (!mem_size_) mem_size_ = jsgraph()->Int32Constant(size);
+ if (!mem_size_)
+ mem_size_ = jsgraph()->RelocatableInt32Constant(
+ size, RelocInfo::WASM_MEMORY_SIZE_REFERENCE);
return mem_size_;
} else {
- return jsgraph()->Int32Constant(size + offset);
+ return jsgraph()->RelocatableInt32Constant(
+ size + offset, RelocInfo::WASM_MEMORY_SIZE_REFERENCE);
}
}
@@ -2579,29 +2582,28 @@ void WasmGraphBuilder::BoundsCheckMem(MachineType memtype, Node* index,
size_t size = module_->instance->mem_size;
byte memsize = wasm::WasmOpcodes::MemSize(memtype);
+ // Check against the effective size.
+ size_t effective_size;
if (offset >= size || (static_cast<uint64_t>(offset) + memsize) > size) {
- // The access will always throw (unless memory is grown).
- Node* cond = jsgraph()->Int32Constant(0);
- trap_->AddTrapIfFalse(wasm::kTrapMemOutOfBounds, cond, position);
- return;
+ effective_size = 0;
+ } else {
+ effective_size = size - offset - memsize + 1;
}
-
- // Check against the effective size.
- size_t effective_size = size - offset - memsize;
CHECK(effective_size <= kMaxUInt32);
Uint32Matcher m(index);
if (m.HasValue()) {
uint32_t value = m.Value();
- if (value <= effective_size) {
+ if (value < effective_size) {
// The bounds check will always succeed.
return;
}
}
- Node* cond = graph()->NewNode(
- jsgraph()->machine()->Uint32LessThanOrEqual(), index,
- jsgraph()->Int32Constant(static_cast<uint32_t>(effective_size)));
+ Node* cond = graph()->NewNode(jsgraph()->machine()->Uint32LessThan(), index,
+ jsgraph()->RelocatableInt32Constant(
+ static_cast<uint32_t>(effective_size),
+ RelocInfo::WASM_MEMORY_SIZE_REFERENCE));
trap_->AddTrapIfFalse(wasm::kTrapMemOutOfBounds, cond, position);
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698