[wasm] memory size is an uint32_t, not a size_t.

BUG=

Review-Url: https://codereview.chromium.org/2077623002
Cr-Commit-Position: refs/heads/master@{#37044}
This commit is contained in:
mtrofin 2016-06-16 15:21:30 -07:00 committed by Commit bot
parent 6710159716
commit 273bb58c33
4 changed files with 56 additions and 56 deletions

View File

@ -2578,7 +2578,7 @@ void WasmGraphBuilder::BoundsCheckMem(MachineType memtype, Node* index,
uint32_t offset,
wasm::WasmCodePosition position) {
DCHECK(module_ && module_->instance);
size_t size = module_->instance->mem_size;
uint32_t size = module_->instance->mem_size;
byte memsize = wasm::WasmOpcodes::MemSize(memtype);
// Check against the effective size.

View File

@ -225,7 +225,7 @@ struct WasmModuleInstance {
std::vector<Handle<Code>> import_code; // code objects for each import.
// -- raw memory ------------------------------------------------------------
byte* mem_start; // start of linear memory.
size_t mem_size; // size of the linear memory.
uint32_t mem_size; // size of the linear memory.
// -- raw globals -----------------------------------------------------------
byte* globals_start; // start of the globals area.

View File

@ -51,7 +51,7 @@ WASM_EXEC_TEST(Int8Const_fallthru2) {
}
WASM_EXEC_TEST(Int8Const_all) {
for (int value = -128; value <= 127; value++) {
for (int value = -128; value <= 127; ++value) {
WasmRunner<int32_t> r(execution_mode);
// return(value)
BUILD(r, WASM_I8(value));
@ -400,10 +400,10 @@ WASM_EXEC_TEST(Int32RemU_trap) {
}
WASM_EXEC_TEST(Int32DivS_byzero_const) {
for (int8_t denom = -2; denom < 8; denom++) {
for (int8_t denom = -2; denom < 8; ++denom) {
WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
BUILD(r, WASM_I32_DIVS(WASM_GET_LOCAL(0), WASM_I8(denom)));
for (int32_t val = -7; val < 8; val++) {
for (int32_t val = -7; val < 8; ++val) {
if (denom == 0) {
CHECK_TRAP(r.Call(val));
} else {
@ -414,11 +414,11 @@ WASM_EXEC_TEST(Int32DivS_byzero_const) {
}
WASM_EXEC_TEST(Int32DivU_byzero_const) {
for (uint32_t denom = 0xfffffffe; denom < 8; denom++) {
for (uint32_t denom = 0xfffffffe; denom < 8; ++denom) {
WasmRunner<uint32_t> r(execution_mode, MachineType::Uint32());
BUILD(r, WASM_I32_DIVU(WASM_GET_LOCAL(0), WASM_I32V_1(denom)));
for (uint32_t val = 0xfffffff0; val < 8; val++) {
for (uint32_t val = 0xfffffff0; val < 8; ++val) {
if (denom == 0) {
CHECK_TRAP(r.Call(val));
} else {
@ -891,8 +891,8 @@ WASM_EXEC_TEST(BrTable_br2) {
}
WASM_EXEC_TEST(BrTable4) {
for (int i = 0; i < 4; i++) {
for (int t = 0; t < 4; t++) {
for (int i = 0; i < 4; ++i) {
for (int t = 0; t < 4; ++t) {
uint32_t cases[] = {0, 1, 2, 3};
cases[i] = t;
byte code[] = {B2(B2(B2(B2(B1(WASM_BR_TABLE(
@ -908,7 +908,7 @@ WASM_EXEC_TEST(BrTable4) {
WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
r.Build(code, code + arraysize(code));
for (int x = -3; x < 50; x++) {
for (int x = -3; x < 50; ++x) {
int index = (x > 3 || x < 0) ? 3 : x;
int32_t expected = 70 + cases[index];
CHECK_EQ(expected, r.Call(x));
@ -918,11 +918,11 @@ WASM_EXEC_TEST(BrTable4) {
}
WASM_EXEC_TEST(BrTable4x4) {
for (byte a = 0; a < 4; a++) {
for (byte b = 0; b < 4; b++) {
for (byte c = 0; c < 4; c++) {
for (byte d = 0; d < 4; d++) {
for (int i = 0; i < 4; i++) {
for (byte a = 0; a < 4; ++a) {
for (byte b = 0; b < 4; ++b) {
for (byte c = 0; c < 4; ++c) {
for (byte d = 0; d < 4; ++d) {
for (int i = 0; i < 4; ++i) {
uint32_t cases[] = {a, b, c, d};
byte code[] = {
B2(B2(B2(B2(B1(WASM_BR_TABLE(
@ -938,7 +938,7 @@ WASM_EXEC_TEST(BrTable4x4) {
WasmRunner<int32_t> r(execution_mode, MachineType::Int32());
r.Build(code, code + arraysize(code));
for (int x = -6; x < 47; x++) {
for (int x = -6; x < 47; ++x) {
int index = (x > 3 || x < 0) ? 3 : x;
int32_t expected = 50 + cases[index];
CHECK_EQ(expected, r.Call(x));
@ -1322,7 +1322,7 @@ WASM_EXEC_TEST(LoadMemI32) {
WASM_EXEC_TEST(LoadMemI32_alignment) {
TestingModule module(execution_mode);
int32_t* memory = module.AddMemoryElems<int32_t>(8);
for (byte alignment = 0; alignment <= 2; alignment++) {
for (byte alignment = 0; alignment <= 2; ++alignment) {
WasmRunner<int32_t> r(&module, MachineType::Int32());
module.RandomizeMemory(1111);
@ -1350,11 +1350,11 @@ WASM_EXEC_TEST(LoadMemI32_oob) {
memory[0] = 88888888;
CHECK_EQ(88888888, r.Call(0u));
for (uint32_t offset = 29; offset < 40; offset++) {
for (uint32_t offset = 29; offset < 40; ++offset) {
CHECK_TRAP(r.Call(offset));
}
for (uint32_t offset = 0x80000000; offset < 0x80000010; offset++) {
for (uint32_t offset = 0x80000000; offset < 0x80000010; ++offset) {
CHECK_TRAP(r.Call(offset));
}
}
@ -1369,7 +1369,7 @@ WASM_EXEC_TEST(LoadMem_offset_oob) {
MachineType::Int64(), MachineType::Uint64(), MachineType::Float32(),
MachineType::Float64()};
for (size_t m = 0; m < arraysize(machineTypes); m++) {
for (size_t m = 0; m < arraysize(machineTypes); ++m) {
module.RandomizeMemory(1116 + static_cast<int>(m));
WasmRunner<int32_t> r(&module, MachineType::Uint32());
uint32_t boundary = 24 - WasmOpcodes::MemSize(machineTypes[m]);
@ -1379,7 +1379,7 @@ WASM_EXEC_TEST(LoadMem_offset_oob) {
CHECK_EQ(0, r.Call(boundary)); // in bounds.
for (uint32_t offset = boundary + 1; offset < boundary + 19; offset++) {
for (uint32_t offset = boundary + 1; offset < boundary + 19; ++offset) {
CHECK_TRAP(r.Call(offset)); // out of bounds.
}
}
@ -1413,8 +1413,8 @@ WASM_EXEC_TEST(LoadMemI32_offset) {
WASM_EXEC_TEST(LoadMemI32_const_oob_misaligned) {
const int kMemSize = 12;
// TODO(titzer): Fix misaligned accesses on MIPS and re-enable.
for (int offset = 0; offset < kMemSize + 5; offset++) {
for (int index = 0; index < kMemSize + 5; index++) {
for (int offset = 0; offset < kMemSize + 5; ++offset) {
for (int index = 0; index < kMemSize + 5; ++index) {
TestingModule module(execution_mode);
module.AddMemoryElems<byte>(kMemSize);
@ -1460,7 +1460,7 @@ WASM_EXEC_TEST(StoreMemI32_alignment) {
int32_t* memory = module.AddMemoryElems<int32_t>(4);
const int32_t kWritten = 0x12345678;
for (byte i = 0; i <= 2; i++) {
for (byte i = 0; i <= 2; ++i) {
WasmRunner<int32_t> r(&module, MachineType::Int32());
BUILD(r, WASM_STORE_MEM_ALIGNMENT(MachineType::Int32(), WASM_ZERO, i,
WASM_GET_LOCAL(0)));
@ -1481,7 +1481,7 @@ WASM_EXEC_TEST(StoreMemI32_offset) {
BUILD(r, WASM_STORE_MEM_OFFSET(MachineType::Int32(), 4, WASM_GET_LOCAL(0),
WASM_I32V_5(kWritten)));
for (int i = 0; i < 2; i++) {
for (int i = 0; i < 2; ++i) {
module.RandomizeMemory(1111);
memory[0] = 66666666;
memory[1] = 77777777;
@ -1505,7 +1505,7 @@ WASM_EXEC_TEST(StoreMem_offset_oob) {
MachineType::Uint16(), MachineType::Int32(), MachineType::Uint32(),
MachineType::Float32(), MachineType::Float64()};
for (size_t m = 0; m < arraysize(machineTypes); m++) {
for (size_t m = 0; m < arraysize(machineTypes); ++m) {
module.RandomizeMemory(1119 + static_cast<int>(m));
WasmRunner<int32_t> r(&module, MachineType::Uint32());
@ -1518,7 +1518,7 @@ WASM_EXEC_TEST(StoreMem_offset_oob) {
CHECK_EQ(0, r.Call(boundary)); // in bounds.
CHECK_EQ(0, memcmp(&memory[0], &memory[8 + boundary], memsize));
for (uint32_t offset = boundary + 1; offset < boundary + 19; offset++) {
for (uint32_t offset = boundary + 1; offset < boundary + 19; ++offset) {
CHECK_TRAP(r.Call(offset)); // out of bounds.
}
}
@ -1533,7 +1533,7 @@ WASM_EXEC_TEST(LoadMemI32_P) {
BUILD(r, WASM_LOAD_MEM(MachineType::Int32(), WASM_GET_LOCAL(0)));
for (int i = 0; i < kNumElems; i++) {
for (int i = 0; i < kNumElems; ++i) {
CHECK_EQ(memory[i], r.Call(i * 4));
}
}
@ -1559,13 +1559,13 @@ WASM_EXEC_TEST(MemI32_Sum) {
WASM_GET_LOCAL(1)));
// Run 4 trials.
for (int i = 0; i < 3; i++) {
for (int i = 0; i < 3; ++i) {
module.RandomizeMemory(i * 33);
uint32_t expected = 0;
for (size_t j = kNumElems - 1; j > 0; j--) {
for (size_t j = kNumElems - 1; j > 0; --j) {
expected += memory[j];
}
uint32_t result = r.Call(static_cast<int>(4 * (kNumElems - 1)));
uint32_t result = r.Call(4 * (kNumElems - 1));
CHECK_EQ(expected, result);
}
}
@ -1620,11 +1620,11 @@ WASM_EXEC_TEST(MemF32_Sum) {
template <typename T>
T GenerateAndRunFold(WasmExecutionMode execution_mode, WasmOpcode binop,
T* buffer, size_t size, LocalType astType,
T* buffer, uint32_t size, LocalType astType,
MachineType memType) {
TestingModule module(execution_mode);
module.AddMemoryElems<T>(size);
for (size_t i = 0; i < size; i++) {
for (uint32_t i = 0; i < size; ++i) {
module.raw_mem_start<T>()[i] = buffer[i];
}
WasmRunner<int32_t> r(&module, MachineType::Int32());
@ -1788,8 +1788,8 @@ WASM_EXEC_TEST(Int32LoadInt8_signext) {
WasmRunner<int32_t> r(&module, MachineType::Int32());
BUILD(r, WASM_LOAD_MEM(MachineType::Int8(), WASM_GET_LOCAL(0)));
for (size_t i = 0; i < kNumElems; i++) {
CHECK_EQ(memory[i], r.Call(static_cast<int>(i)));
for (int i = 0; i < kNumElems; ++i) {
CHECK_EQ(memory[i], r.Call(i));
}
}
@ -1802,8 +1802,8 @@ WASM_EXEC_TEST(Int32LoadInt8_zeroext) {
WasmRunner<int32_t> r(&module, MachineType::Int32());
BUILD(r, WASM_LOAD_MEM(MachineType::Uint8(), WASM_GET_LOCAL(0)));
for (size_t i = 0; i < kNumElems; i++) {
CHECK_EQ(memory[i], r.Call(static_cast<int>(i)));
for (int i = 0; i < kNumElems; ++i) {
CHECK_EQ(memory[i], r.Call(i));
}
}
@ -1816,9 +1816,9 @@ WASM_EXEC_TEST(Int32LoadInt16_signext) {
WasmRunner<int32_t> r(&module, MachineType::Int32());
BUILD(r, WASM_LOAD_MEM(MachineType::Int16(), WASM_GET_LOCAL(0)));
for (size_t i = 0; i < kNumBytes; i += 2) {
for (int i = 0; i < kNumBytes; i += 2) {
int32_t expected = memory[i] | (static_cast<int8_t>(memory[i + 1]) << 8);
CHECK_EQ(expected, r.Call(static_cast<int>(i)));
CHECK_EQ(expected, r.Call(i));
}
}
@ -1831,9 +1831,9 @@ WASM_EXEC_TEST(Int32LoadInt16_zeroext) {
WasmRunner<int32_t> r(&module, MachineType::Int32());
BUILD(r, WASM_LOAD_MEM(MachineType::Uint16(), WASM_GET_LOCAL(0)));
for (size_t i = 0; i < kNumBytes; i += 2) {
for (int i = 0; i < kNumBytes; i += 2) {
int32_t expected = memory[i] | (memory[i + 1] << 8);
CHECK_EQ(expected, r.Call(static_cast<int>(i)));
CHECK_EQ(expected, r.Call(i));
}
}
@ -1860,7 +1860,7 @@ WASM_EXEC_TEST(Int32Globals_DontAlias) {
module.AddGlobal<int32_t>(MachineType::Int32()),
module.AddGlobal<int32_t>(MachineType::Int32())};
for (int g = 0; g < kNumGlobals; g++) {
for (int g = 0; g < kNumGlobals; ++g) {
// global = global + p0
WasmRunner<int32_t> r(&module, MachineType::Int32());
BUILD(r, WASM_STORE_GLOBAL(
@ -1871,9 +1871,9 @@ WASM_EXEC_TEST(Int32Globals_DontAlias) {
int32_t before[kNumGlobals];
for (int i = 9; i < 444444; i += 111113) {
int32_t sum = *globals[g] + i;
for (int j = 0; j < kNumGlobals; j++) before[j] = *globals[j];
for (int j = 0; j < kNumGlobals; ++j) before[j] = *globals[j];
r.Call(i);
for (int j = 0; j < kNumGlobals; j++) {
for (int j = 0; j < kNumGlobals; ++j) {
int32_t expected = j == g ? sum : before[j];
CHECK_EQ(expected, *globals[j]);
}
@ -1991,7 +1991,7 @@ WASM_EXEC_TEST(CallEmpty) {
WASM_EXEC_TEST(CallF32StackParameter) {
// Build the target function.
LocalType param_types[20];
for (int i = 0; i < 20; i++) param_types[i] = kAstF32;
for (int i = 0; i < 20; ++i) param_types[i] = kAstF32;
FunctionSig sig(1, 19, param_types);
TestingModule module(execution_mode);
WasmFunctionCompiler t(&sig, &module);
@ -2015,7 +2015,7 @@ WASM_EXEC_TEST(CallF32StackParameter) {
WASM_EXEC_TEST(CallF64StackParameter) {
// Build the target function.
LocalType param_types[20];
for (int i = 0; i < 20; i++) param_types[i] = kAstF64;
for (int i = 0; i < 20; ++i) param_types[i] = kAstF64;
FunctionSig sig(1, 19, param_types);
TestingModule module(execution_mode);
WasmFunctionCompiler t(&sig, &module);
@ -2130,7 +2130,7 @@ WASM_EXEC_TEST(Call_Float64Sub) {
#define ADD_CODE(vec, ...) \
do { \
byte __buf[] = {__VA_ARGS__}; \
for (size_t i = 0; i < sizeof(__buf); i++) vec.push_back(__buf[i]); \
for (size_t i = 0; i < sizeof(__buf); ++i) vec.push_back(__buf[i]); \
} while (false)
static void Run_WasmMixedCall_N(WasmExecutionMode execution_mode, int start) {
@ -2146,7 +2146,7 @@ static void Run_WasmMixedCall_N(WasmExecutionMode execution_mode, int start) {
MachineType::Int32(), MachineType::Int32()};
int num_params = static_cast<int>(arraysize(mixed)) - start;
for (int which = 0; which < num_params; which++) {
for (int which = 0; which < num_params; ++which) {
v8::base::AccountingAllocator allocator;
Zone zone(&allocator);
TestingModule module(execution_mode);
@ -2160,7 +2160,7 @@ static void Run_WasmMixedCall_N(WasmExecutionMode execution_mode, int start) {
uint32_t index;
FunctionSig::Builder b(&zone, 1, num_params);
b.AddReturn(WasmOpcodes::LocalTypeFor(result));
for (int i = 0; i < num_params; i++) {
for (int i = 0; i < num_params; ++i) {
b.AddParam(WasmOpcodes::LocalTypeFor(memtypes[i]));
}
WasmFunctionCompiler t(b.Build(), &module);
@ -2177,7 +2177,7 @@ static void Run_WasmMixedCall_N(WasmExecutionMode execution_mode, int start) {
ADD_CODE(code, WASM_ZERO);
// Load the arguments.
for (int i = 0; i < num_params; i++) {
for (int i = 0; i < num_params; ++i) {
int offset = (i + 1) * kElemSize;
ADD_CODE(code, WASM_LOAD_MEM(memtypes[i], WASM_I8(offset)));
}
@ -2197,12 +2197,12 @@ static void Run_WasmMixedCall_N(WasmExecutionMode execution_mode, int start) {
r.Build(&code[0], &code[0] + code.size());
// Run the code.
for (int t = 0; t < 10; t++) {
for (int t = 0; t < 10; ++t) {
module.RandomizeMemory();
CHECK_EQ(kExpected, r.Call());
int size = WasmOpcodes::MemSize(result);
for (int i = 0; i < size; i++) {
for (int i = 0; i < size; ++i) {
int base = (which + 1) * kElemSize;
byte expected = module.raw_mem_at<byte>(base + i);
byte result = module.raw_mem_at<byte>(i);
@ -2778,7 +2778,7 @@ static void CompileCallIndirectMany(LocalType param) {
// Make sure we don't run out of registers when compiling indirect calls
// with many many parameters.
TestSignatures sigs;
for (byte num_params = 0; num_params < 40; num_params++) {
for (byte num_params = 0; num_params < 40; ++num_params) {
v8::base::AccountingAllocator allocator;
Zone zone(&allocator);
HandleScope scope(CcTest::InitIsolateOnce());
@ -2793,7 +2793,7 @@ static void CompileCallIndirectMany(LocalType param) {
std::vector<byte> code;
ADD_CODE(code, kExprI8Const, 0);
for (byte p = 0; p < num_params; p++) {
for (byte p = 0; p < num_params; ++p) {
ADD_CODE(code, kExprGetLocal, p);
}
ADD_CODE(code, kExprCallIndirect, static_cast<byte>(num_params), 1);

View File

@ -96,7 +96,7 @@ class TestingModule : public ModuleEnv {
if (interpreter_) delete interpreter_;
}
byte* AddMemory(size_t size) {
byte* AddMemory(uint32_t size) {
CHECK_NULL(instance->mem_start);
CHECK_EQ(0, instance->mem_size);
instance->mem_start = reinterpret_cast<byte*>(malloc(size));
@ -107,7 +107,7 @@ class TestingModule : public ModuleEnv {
}
template <typename T>
T* AddMemoryElems(size_t count) {
T* AddMemoryElems(uint32_t count) {
AddMemory(count * sizeof(T));
return raw_mem_start<T>();
}