Commit efa03836 authored by Andreas Haas's avatar Andreas Haas Committed by Commit Bot

[wasm][cleanup] Use enums for template parameter values instead of bool

Calls like read_leb<int32_t, true, true, true>(...) can be hard to read
and understand. This CL replaces the three boolean template parameters
with enums so that the call is read_leb<int32_t, kChecked, kAdvancePC, kTrace>(...)
now.

R=clemensh@chromium.org

Bug: v8:6921
Change-Id: Id876a727d5e17df721444e7e5a117ad5395071aa
Reviewed-on: https://chromium-review.googlesource.com/718204
Commit-Queue: Andreas Haas <ahaas@chromium.org>
Reviewed-by: 's avatarClemens Hammacher <clemensh@chromium.org>
Reviewed-by: 's avatarBen Titzer <titzer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#48607}
parent d0e3fb4f
...@@ -43,6 +43,12 @@ using DecodeResult = Result<std::nullptr_t>; ...@@ -43,6 +43,12 @@ using DecodeResult = Result<std::nullptr_t>;
// a buffer of bytes. // a buffer of bytes.
class Decoder { class Decoder {
public: public:
enum ValidateFlag : bool { kValidate = true, kNoValidate = false };
enum AdvancePCFlag : bool { kAdvancePc = true, kNoAdvancePc = false };
enum TraceFlag : bool { kTrace = true, kNoTrace = false };
Decoder(const byte* start, const byte* end, uint32_t buffer_offset = 0) Decoder(const byte* start, const byte* end, uint32_t buffer_offset = 0)
: start_(start), pc_(start), end_(end), buffer_offset_(buffer_offset) {} : start_(start), pc_(start), end_(end), buffer_offset_(buffer_offset) {}
Decoder(const byte* start, const byte* pc, const byte* end, Decoder(const byte* start, const byte* pc, const byte* end,
...@@ -51,7 +57,7 @@ class Decoder { ...@@ -51,7 +57,7 @@ class Decoder {
virtual ~Decoder() {} virtual ~Decoder() {}
inline bool check(const byte* pc, uint32_t length, const char* msg) { inline bool validate_size(const byte* pc, uint32_t length, const char* msg) {
DCHECK_LE(start_, pc); DCHECK_LE(start_, pc);
if (V8_UNLIKELY(pc + length > end_)) { if (V8_UNLIKELY(pc + length > end_)) {
error(pc, msg); error(pc, msg);
...@@ -61,58 +67,62 @@ class Decoder { ...@@ -61,58 +67,62 @@ class Decoder {
} }
// Reads an 8-bit unsigned integer. // Reads an 8-bit unsigned integer.
template <bool checked> template <ValidateFlag validate>
inline uint8_t read_u8(const byte* pc, const char* msg = "expected 1 byte") { inline uint8_t read_u8(const byte* pc, const char* msg = "expected 1 byte") {
return read_little_endian<uint8_t, checked>(pc, msg); return read_little_endian<uint8_t, validate>(pc, msg);
} }
// Reads a 16-bit unsigned integer (little endian). // Reads a 16-bit unsigned integer (little endian).
template <bool checked> template <ValidateFlag validate>
inline uint16_t read_u16(const byte* pc, inline uint16_t read_u16(const byte* pc,
const char* msg = "expected 2 bytes") { const char* msg = "expected 2 bytes") {
return read_little_endian<uint16_t, checked>(pc, msg); return read_little_endian<uint16_t, validate>(pc, msg);
} }
// Reads a 32-bit unsigned integer (little endian). // Reads a 32-bit unsigned integer (little endian).
template <bool checked> template <ValidateFlag validate>
inline uint32_t read_u32(const byte* pc, inline uint32_t read_u32(const byte* pc,
const char* msg = "expected 4 bytes") { const char* msg = "expected 4 bytes") {
return read_little_endian<uint32_t, checked>(pc, msg); return read_little_endian<uint32_t, validate>(pc, msg);
} }
// Reads a 64-bit unsigned integer (little endian). // Reads a 64-bit unsigned integer (little endian).
template <bool checked> template <ValidateFlag validate>
inline uint64_t read_u64(const byte* pc, inline uint64_t read_u64(const byte* pc,
const char* msg = "expected 8 bytes") { const char* msg = "expected 8 bytes") {
return read_little_endian<uint64_t, checked>(pc, msg); return read_little_endian<uint64_t, validate>(pc, msg);
} }
// Reads a variable-length unsigned integer (little endian). // Reads a variable-length unsigned integer (little endian).
template <bool checked> template <ValidateFlag validate>
uint32_t read_u32v(const byte* pc, uint32_t* length, uint32_t read_u32v(const byte* pc, uint32_t* length,
const char* name = "LEB32") { const char* name = "LEB32") {
return read_leb<uint32_t, checked, false, false>(pc, length, name); return read_leb<uint32_t, validate, kNoAdvancePc, kNoTrace>(pc, length,
name);
} }
// Reads a variable-length signed integer (little endian). // Reads a variable-length signed integer (little endian).
template <bool checked> template <ValidateFlag validate>
int32_t read_i32v(const byte* pc, uint32_t* length, int32_t read_i32v(const byte* pc, uint32_t* length,
const char* name = "signed LEB32") { const char* name = "signed LEB32") {
return read_leb<int32_t, checked, false, false>(pc, length, name); return read_leb<int32_t, validate, kNoAdvancePc, kNoTrace>(pc, length,
name);
} }
// Reads a variable-length unsigned integer (little endian). // Reads a variable-length unsigned integer (little endian).
template <bool checked> template <ValidateFlag validate>
uint64_t read_u64v(const byte* pc, uint32_t* length, uint64_t read_u64v(const byte* pc, uint32_t* length,
const char* name = "LEB64") { const char* name = "LEB64") {
return read_leb<uint64_t, checked, false, false>(pc, length, name); return read_leb<uint64_t, validate, kNoAdvancePc, kNoTrace>(pc, length,
name);
} }
// Reads a variable-length signed integer (little endian). // Reads a variable-length signed integer (little endian).
template <bool checked> template <ValidateFlag validate>
int64_t read_i64v(const byte* pc, uint32_t* length, int64_t read_i64v(const byte* pc, uint32_t* length,
const char* name = "signed LEB64") { const char* name = "signed LEB64") {
return read_leb<int64_t, checked, false, false>(pc, length, name); return read_leb<int64_t, validate, kNoAdvancePc, kNoTrace>(pc, length,
name);
} }
// Reads a 8-bit unsigned integer (byte) and advances {pc_}. // Reads a 8-bit unsigned integer (byte) and advances {pc_}.
...@@ -133,13 +143,14 @@ class Decoder { ...@@ -133,13 +143,14 @@ class Decoder {
// Reads a LEB128 variable-length unsigned 32-bit integer and advances {pc_}. // Reads a LEB128 variable-length unsigned 32-bit integer and advances {pc_}.
uint32_t consume_u32v(const char* name = nullptr) { uint32_t consume_u32v(const char* name = nullptr) {
uint32_t length = 0; uint32_t length = 0;
return read_leb<uint32_t, true, true, true>(pc_, &length, name); return read_leb<uint32_t, kValidate, kAdvancePc, kTrace>(pc_, &length,
name);
} }
// Reads a LEB128 variable-length signed 32-bit integer and advances {pc_}. // Reads a LEB128 variable-length signed 32-bit integer and advances {pc_}.
int32_t consume_i32v(const char* name = nullptr) { int32_t consume_i32v(const char* name = nullptr) {
uint32_t length = 0; uint32_t length = 0;
return read_leb<int32_t, true, true, true>(pc_, &length, name); return read_leb<int32_t, kValidate, kAdvancePc, kTrace>(pc_, &length, name);
} }
// Consume {size} bytes and send them to the bit bucket, advancing {pc_}. // Consume {size} bytes and send them to the bit bucket, advancing {pc_}.
...@@ -261,11 +272,11 @@ class Decoder { ...@@ -261,11 +272,11 @@ class Decoder {
std::string error_msg_; std::string error_msg_;
private: private:
template <typename IntType, bool checked> template <typename IntType, bool validate>
inline IntType read_little_endian(const byte* pc, const char* msg) { inline IntType read_little_endian(const byte* pc, const char* msg) {
if (!checked) { if (!validate) {
DCHECK(check(pc, sizeof(IntType), msg)); DCHECK(validate_size(pc, sizeof(IntType), msg));
} else if (!check(pc, sizeof(IntType), msg)) { } else if (!validate_size(pc, sizeof(IntType), msg)) {
return IntType{0}; return IntType{0};
} }
return ReadLittleEndianValue<IntType>(pc); return ReadLittleEndianValue<IntType>(pc);
...@@ -286,17 +297,18 @@ class Decoder { ...@@ -286,17 +297,18 @@ class Decoder {
return val; return val;
} }
template <typename IntType, bool checked, bool advance_pc, bool trace> template <typename IntType, ValidateFlag validate, AdvancePCFlag advance_pc,
TraceFlag trace>
inline IntType read_leb(const byte* pc, uint32_t* length, inline IntType read_leb(const byte* pc, uint32_t* length,
const char* name = "varint") { const char* name = "varint") {
DCHECK_IMPLIES(advance_pc, pc == pc_); DCHECK_IMPLIES(advance_pc, pc == pc_);
TRACE_IF(trace, " +%u %-20s: ", pc_offset(), name); TRACE_IF(trace, " +%u %-20s: ", pc_offset(), name);
return read_leb_tail<IntType, checked, advance_pc, trace, 0>(pc, length, return read_leb_tail<IntType, validate, advance_pc, trace, 0>(pc, length,
name, 0); name, 0);
} }
template <typename IntType, bool checked, bool advance_pc, bool trace, template <typename IntType, ValidateFlag validate, AdvancePCFlag advance_pc,
int byte_index> TraceFlag trace, int byte_index>
IntType read_leb_tail(const byte* pc, uint32_t* length, const char* name, IntType read_leb_tail(const byte* pc, uint32_t* length, const char* name,
IntType result) { IntType result) {
constexpr bool is_signed = std::is_signed<IntType>::value; constexpr bool is_signed = std::is_signed<IntType>::value;
...@@ -304,7 +316,7 @@ class Decoder { ...@@ -304,7 +316,7 @@ class Decoder {
static_assert(byte_index < kMaxLength, "invalid template instantiation"); static_assert(byte_index < kMaxLength, "invalid template instantiation");
constexpr int shift = byte_index * 7; constexpr int shift = byte_index * 7;
constexpr bool is_last_byte = byte_index == kMaxLength - 1; constexpr bool is_last_byte = byte_index == kMaxLength - 1;
const bool at_end = checked && pc >= end_; const bool at_end = validate && pc >= end_;
byte b = 0; byte b = 0;
if (!at_end) { if (!at_end) {
DCHECK_LT(pc, end_); DCHECK_LT(pc, end_);
...@@ -317,12 +329,12 @@ class Decoder { ...@@ -317,12 +329,12 @@ class Decoder {
// Compilers are not smart enough to figure out statically that the // Compilers are not smart enough to figure out statically that the
// following call is unreachable if is_last_byte is false. // following call is unreachable if is_last_byte is false.
constexpr int next_byte_index = byte_index + (is_last_byte ? 0 : 1); constexpr int next_byte_index = byte_index + (is_last_byte ? 0 : 1);
return read_leb_tail<IntType, checked, advance_pc, trace, return read_leb_tail<IntType, validate, advance_pc, trace,
next_byte_index>(pc + 1, length, name, result); next_byte_index>(pc + 1, length, name, result);
} }
if (advance_pc) pc_ = pc + (at_end ? 0 : 1); if (advance_pc) pc_ = pc + (at_end ? 0 : 1);
*length = byte_index + (at_end ? 0 : 1); *length = byte_index + (at_end ? 0 : 1);
if (checked && (at_end || (b & 0x80))) { if (validate && (at_end || (b & 0x80))) {
TRACE_IF(trace, at_end ? "<end> " : "<length overflow> "); TRACE_IF(trace, at_end ? "<end> " : "<length overflow> ");
errorf(pc, "expected %s", name); errorf(pc, "expected %s", name);
result = 0; result = 0;
...@@ -341,7 +353,7 @@ class Decoder { ...@@ -341,7 +353,7 @@ class Decoder {
bool valid_extra_bits = bool valid_extra_bits =
checked_bits == 0 || checked_bits == 0 ||
(is_signed && checked_bits == kSignExtendedExtraBits); (is_signed && checked_bits == kSignExtendedExtraBits);
if (!checked) { if (!validate) {
DCHECK(valid_extra_bits); DCHECK(valid_extra_bits);
} else if (!valid_extra_bits) { } else if (!valid_extra_bits) {
error(pc, "extra bits in varint"); error(pc, "extra bits in varint");
......
...@@ -87,7 +87,7 @@ Vector<T> vec2vec(std::vector<T>& vec) { ...@@ -87,7 +87,7 @@ Vector<T> vec2vec(std::vector<T>& vec) {
} }
// Helpers for decoding different kinds of operands which follow bytecodes. // Helpers for decoding different kinds of operands which follow bytecodes.
template <bool validate> template <Decoder::ValidateFlag validate>
struct LocalIndexOperand { struct LocalIndexOperand {
uint32_t index; uint32_t index;
ValueType type = kWasmStmt; ValueType type = kWasmStmt;
...@@ -98,7 +98,7 @@ struct LocalIndexOperand { ...@@ -98,7 +98,7 @@ struct LocalIndexOperand {
} }
}; };
template <bool validate> template <Decoder::ValidateFlag validate>
struct ExceptionIndexOperand { struct ExceptionIndexOperand {
uint32_t index; uint32_t index;
const WasmException* exception = nullptr; const WasmException* exception = nullptr;
...@@ -109,7 +109,7 @@ struct ExceptionIndexOperand { ...@@ -109,7 +109,7 @@ struct ExceptionIndexOperand {
} }
}; };
template <bool validate> template <Decoder::ValidateFlag validate>
struct ImmI32Operand { struct ImmI32Operand {
int32_t value; int32_t value;
unsigned length; unsigned length;
...@@ -118,7 +118,7 @@ struct ImmI32Operand { ...@@ -118,7 +118,7 @@ struct ImmI32Operand {
} }
}; };
template <bool validate> template <Decoder::ValidateFlag validate>
struct ImmI64Operand { struct ImmI64Operand {
int64_t value; int64_t value;
unsigned length; unsigned length;
...@@ -127,7 +127,7 @@ struct ImmI64Operand { ...@@ -127,7 +127,7 @@ struct ImmI64Operand {
} }
}; };
template <bool validate> template <Decoder::ValidateFlag validate>
struct ImmF32Operand { struct ImmF32Operand {
float value; float value;
unsigned length = 4; unsigned length = 4;
...@@ -138,7 +138,7 @@ struct ImmF32Operand { ...@@ -138,7 +138,7 @@ struct ImmF32Operand {
} }
}; };
template <bool validate> template <Decoder::ValidateFlag validate>
struct ImmF64Operand { struct ImmF64Operand {
double value; double value;
unsigned length = 8; unsigned length = 8;
...@@ -149,7 +149,7 @@ struct ImmF64Operand { ...@@ -149,7 +149,7 @@ struct ImmF64Operand {
} }
}; };
template <bool validate> template <Decoder::ValidateFlag validate>
struct GlobalIndexOperand { struct GlobalIndexOperand {
uint32_t index; uint32_t index;
ValueType type = kWasmStmt; ValueType type = kWasmStmt;
...@@ -161,7 +161,7 @@ struct GlobalIndexOperand { ...@@ -161,7 +161,7 @@ struct GlobalIndexOperand {
} }
}; };
template <bool validate> template <Decoder::ValidateFlag validate>
struct BlockTypeOperand { struct BlockTypeOperand {
unsigned length = 1; unsigned length = 1;
ValueType type = kWasmStmt; ValueType type = kWasmStmt;
...@@ -235,7 +235,7 @@ struct BlockTypeOperand { ...@@ -235,7 +235,7 @@ struct BlockTypeOperand {
} }
}; };
template <bool validate> template <Decoder::ValidateFlag validate>
struct BreakDepthOperand { struct BreakDepthOperand {
uint32_t depth; uint32_t depth;
unsigned length; unsigned length;
...@@ -244,7 +244,7 @@ struct BreakDepthOperand { ...@@ -244,7 +244,7 @@ struct BreakDepthOperand {
} }
}; };
template <bool validate> template <Decoder::ValidateFlag validate>
struct CallIndirectOperand { struct CallIndirectOperand {
uint32_t table_index; uint32_t table_index;
uint32_t index; uint32_t index;
...@@ -262,7 +262,7 @@ struct CallIndirectOperand { ...@@ -262,7 +262,7 @@ struct CallIndirectOperand {
} }
}; };
template <bool validate> template <Decoder::ValidateFlag validate>
struct CallFunctionOperand { struct CallFunctionOperand {
uint32_t index; uint32_t index;
FunctionSig* sig = nullptr; FunctionSig* sig = nullptr;
...@@ -272,7 +272,7 @@ struct CallFunctionOperand { ...@@ -272,7 +272,7 @@ struct CallFunctionOperand {
} }
}; };
template <bool validate> template <Decoder::ValidateFlag validate>
struct MemoryIndexOperand { struct MemoryIndexOperand {
uint32_t index; uint32_t index;
unsigned length = 1; unsigned length = 1;
...@@ -284,7 +284,7 @@ struct MemoryIndexOperand { ...@@ -284,7 +284,7 @@ struct MemoryIndexOperand {
} }
}; };
template <bool validate> template <Decoder::ValidateFlag validate>
struct BranchTableOperand { struct BranchTableOperand {
uint32_t table_count; uint32_t table_count;
const byte* start; const byte* start;
...@@ -299,7 +299,7 @@ struct BranchTableOperand { ...@@ -299,7 +299,7 @@ struct BranchTableOperand {
}; };
// A helper to iterate over a branch table. // A helper to iterate over a branch table.
template <bool validate> template <Decoder::ValidateFlag validate>
class BranchTableIterator { class BranchTableIterator {
public: public:
unsigned cur_index() { return index_; } unsigned cur_index() { return index_; }
...@@ -337,7 +337,7 @@ class BranchTableIterator { ...@@ -337,7 +337,7 @@ class BranchTableIterator {
uint32_t table_count_; // the count of entries, not including default. uint32_t table_count_; // the count of entries, not including default.
}; };
template <bool validate> template <Decoder::ValidateFlag validate>
struct MemoryAccessOperand { struct MemoryAccessOperand {
uint32_t alignment; uint32_t alignment;
uint32_t offset; uint32_t offset;
...@@ -361,7 +361,7 @@ struct MemoryAccessOperand { ...@@ -361,7 +361,7 @@ struct MemoryAccessOperand {
}; };
// Operand for SIMD lane operations. // Operand for SIMD lane operations.
template <bool validate> template <Decoder::ValidateFlag validate>
struct SimdLaneOperand { struct SimdLaneOperand {
uint8_t lane; uint8_t lane;
unsigned length = 1; unsigned length = 1;
...@@ -372,7 +372,7 @@ struct SimdLaneOperand { ...@@ -372,7 +372,7 @@ struct SimdLaneOperand {
}; };
// Operand for SIMD shift operations. // Operand for SIMD shift operations.
template <bool validate> template <Decoder::ValidateFlag validate>
struct SimdShiftOperand { struct SimdShiftOperand {
uint8_t shift; uint8_t shift;
unsigned length = 1; unsigned length = 1;
...@@ -383,7 +383,7 @@ struct SimdShiftOperand { ...@@ -383,7 +383,7 @@ struct SimdShiftOperand {
}; };
// Operand for SIMD S8x16 shuffle operations. // Operand for SIMD S8x16 shuffle operations.
template <bool validate> template <Decoder::ValidateFlag validate>
struct Simd8x16ShuffleOperand { struct Simd8x16ShuffleOperand {
uint8_t shuffle[kSimd128Size]; uint8_t shuffle[kSimd128Size];
...@@ -606,7 +606,7 @@ struct ControlWithNamedConstructors : public ControlBase<Value> { ...@@ -606,7 +606,7 @@ struct ControlWithNamedConstructors : public ControlBase<Value> {
// Generic Wasm bytecode decoder with utilities for decoding operands, // Generic Wasm bytecode decoder with utilities for decoding operands,
// lengths, etc. // lengths, etc.
template <bool validate> template <Decoder::ValidateFlag validate>
class WasmDecoder : public Decoder { class WasmDecoder : public Decoder {
public: public:
WasmDecoder(const WasmModule* module, FunctionSig* sig, const byte* start, WasmDecoder(const WasmModule* module, FunctionSig* sig, const byte* start,
...@@ -703,7 +703,7 @@ class WasmDecoder : public Decoder { ...@@ -703,7 +703,7 @@ class WasmDecoder : public Decoder {
break; break;
case kExprSetLocal: // fallthru case kExprSetLocal: // fallthru
case kExprTeeLocal: { case kExprTeeLocal: {
LocalIndexOperand<validate> operand(decoder, pc); LocalIndexOperand<Decoder::kValidate> operand(decoder, pc);
if (assigned->length() > 0 && if (assigned->length() > 0 &&
operand.index < static_cast<uint32_t>(assigned->length())) { operand.index < static_cast<uint32_t>(assigned->length())) {
// Unverified code might have an out-of-bounds index. // Unverified code might have an out-of-bounds index.
...@@ -733,7 +733,8 @@ class WasmDecoder : public Decoder { ...@@ -733,7 +733,8 @@ class WasmDecoder : public Decoder {
return decoder->ok() ? assigned : nullptr; return decoder->ok() ? assigned : nullptr;
} }
inline bool Validate(const byte* pc, LocalIndexOperand<validate>& operand) { inline bool Validate(const byte* pc,
LocalIndexOperand<Decoder::kValidate>& operand) {
if (!VALIDATE(operand.index < total_locals())) { if (!VALIDATE(operand.index < total_locals())) {
errorf(pc + 1, "invalid local index: %u", operand.index); errorf(pc + 1, "invalid local index: %u", operand.index);
return false; return false;
...@@ -943,7 +944,7 @@ class WasmDecoder : public Decoder { ...@@ -943,7 +944,7 @@ class WasmDecoder : public Decoder {
case kExprSetLocal: case kExprSetLocal:
case kExprTeeLocal: case kExprTeeLocal:
case kExprGetLocal: { case kExprGetLocal: {
LocalIndexOperand<validate> operand(decoder, pc); LocalIndexOperand<Decoder::kValidate> operand(decoder, pc);
return 1 + operand.length; return 1 + operand.length;
} }
case kExprBrTable: { case kExprBrTable: {
...@@ -1103,7 +1104,7 @@ class WasmDecoder : public Decoder { ...@@ -1103,7 +1104,7 @@ class WasmDecoder : public Decoder {
} \ } \
} while (false) } while (false)
template <bool validate, typename Interface> template <Decoder::ValidateFlag validate, typename Interface>
class WasmFullDecoder : public WasmDecoder<validate> { class WasmFullDecoder : public WasmDecoder<validate> {
using Value = typename Interface::Value; using Value = typename Interface::Value;
using Control = typename Interface::Control; using Control = typename Interface::Control;
...@@ -1321,7 +1322,7 @@ class WasmFullDecoder : public WasmDecoder<validate> { ...@@ -1321,7 +1322,7 @@ class WasmFullDecoder : public WasmDecoder<validate> {
} }
case kExprThrow: { case kExprThrow: {
CHECK_PROTOTYPE_OPCODE(eh); CHECK_PROTOTYPE_OPCODE(eh);
ExceptionIndexOperand<true> operand(this, this->pc_); ExceptionIndexOperand<Decoder::kValidate> operand(this, this->pc_);
len = 1 + operand.length; len = 1 + operand.length;
if (!this->Validate(this->pc_, operand)) break; if (!this->Validate(this->pc_, operand)) break;
std::vector<Value> args; std::vector<Value> args;
...@@ -1344,7 +1345,7 @@ class WasmFullDecoder : public WasmDecoder<validate> { ...@@ -1344,7 +1345,7 @@ class WasmFullDecoder : public WasmDecoder<validate> {
case kExprCatch: { case kExprCatch: {
// TODO(kschimpf): Fix to use type signature of exception. // TODO(kschimpf): Fix to use type signature of exception.
CHECK_PROTOTYPE_OPCODE(eh); CHECK_PROTOTYPE_OPCODE(eh);
ExceptionIndexOperand<true> operand(this, this->pc_); ExceptionIndexOperand<Decoder::kValidate> operand(this, this->pc_);
len = 1 + operand.length; len = 1 + operand.length;
if (!this->Validate(this->pc_, operand)) break; if (!this->Validate(this->pc_, operand)) break;
...@@ -1576,7 +1577,7 @@ class WasmFullDecoder : public WasmDecoder<validate> { ...@@ -1576,7 +1577,7 @@ class WasmFullDecoder : public WasmDecoder<validate> {
break; break;
} }
case kExprGetLocal: { case kExprGetLocal: {
LocalIndexOperand<validate> operand(this, this->pc_); LocalIndexOperand<Decoder::kValidate> operand(this, this->pc_);
if (!this->Validate(this->pc_, operand)) break; if (!this->Validate(this->pc_, operand)) break;
auto* value = Push(operand.type); auto* value = Push(operand.type);
CALL_INTERFACE_IF_REACHABLE(GetLocal, value, operand); CALL_INTERFACE_IF_REACHABLE(GetLocal, value, operand);
...@@ -1584,7 +1585,7 @@ class WasmFullDecoder : public WasmDecoder<validate> { ...@@ -1584,7 +1585,7 @@ class WasmFullDecoder : public WasmDecoder<validate> {
break; break;
} }
case kExprSetLocal: { case kExprSetLocal: {
LocalIndexOperand<validate> operand(this, this->pc_); LocalIndexOperand<Decoder::kValidate> operand(this, this->pc_);
if (!this->Validate(this->pc_, operand)) break; if (!this->Validate(this->pc_, operand)) break;
auto value = Pop(0, local_type_vec_[operand.index]); auto value = Pop(0, local_type_vec_[operand.index]);
CALL_INTERFACE_IF_REACHABLE(SetLocal, value, operand); CALL_INTERFACE_IF_REACHABLE(SetLocal, value, operand);
...@@ -1592,7 +1593,7 @@ class WasmFullDecoder : public WasmDecoder<validate> { ...@@ -1592,7 +1593,7 @@ class WasmFullDecoder : public WasmDecoder<validate> {
break; break;
} }
case kExprTeeLocal: { case kExprTeeLocal: {
LocalIndexOperand<validate> operand(this, this->pc_); LocalIndexOperand<Decoder::kValidate> operand(this, this->pc_);
if (!this->Validate(this->pc_, operand)) break; if (!this->Validate(this->pc_, operand)) break;
auto value = Pop(0, local_type_vec_[operand.index]); auto value = Pop(0, local_type_vec_[operand.index]);
auto* result = Push(value.type); auto* result = Push(value.type);
...@@ -1822,7 +1823,7 @@ class WasmFullDecoder : public WasmDecoder<validate> { ...@@ -1822,7 +1823,7 @@ class WasmFullDecoder : public WasmDecoder<validate> {
case kExprGetLocal: case kExprGetLocal:
case kExprSetLocal: case kExprSetLocal:
case kExprTeeLocal: { case kExprTeeLocal: {
LocalIndexOperand<validate> operand(this, val.pc); LocalIndexOperand<Decoder::kValidate> operand(this, val.pc);
PrintF("[%u]", operand.index); PrintF("[%u]", operand.index);
break; break;
} }
...@@ -2330,7 +2331,8 @@ class WasmFullDecoder : public WasmDecoder<validate> { ...@@ -2330,7 +2331,8 @@ class WasmFullDecoder : public WasmDecoder<validate> {
class EmptyInterface { class EmptyInterface {
public: public:
constexpr static bool validate = true; static constexpr wasm::Decoder::ValidateFlag validate =
wasm::Decoder::kValidate;
using Value = ValueBase; using Value = ValueBase;
using Control = ControlBase<Value>; using Control = ControlBase<Value>;
using Decoder = WasmFullDecoder<validate, EmptyInterface>; using Decoder = WasmFullDecoder<validate, EmptyInterface>;
......
This diff is collapsed.
...@@ -178,7 +178,8 @@ class V8_EXPORT_PRIVATE BytecodeIterator : public NON_EXPORTED_BASE(Decoder) { ...@@ -178,7 +178,8 @@ class V8_EXPORT_PRIVATE BytecodeIterator : public NON_EXPORTED_BASE(Decoder) {
} }
WasmOpcode current() { WasmOpcode current() {
return static_cast<WasmOpcode>(read_u8<false>(pc_, "expected bytecode")); return static_cast<WasmOpcode>(
read_u8<Decoder::kNoValidate>(pc_, "expected bytecode"));
} }
void next() { void next() {
...@@ -191,8 +192,8 @@ class V8_EXPORT_PRIVATE BytecodeIterator : public NON_EXPORTED_BASE(Decoder) { ...@@ -191,8 +192,8 @@ class V8_EXPORT_PRIVATE BytecodeIterator : public NON_EXPORTED_BASE(Decoder) {
bool has_next() { return pc_ < end_; } bool has_next() { return pc_ < end_; }
WasmOpcode prefixed_opcode() { WasmOpcode prefixed_opcode() {
byte prefix = read_u8<false>(pc_, "expected prefix"); byte prefix = read_u8<Decoder::kNoValidate>(pc_, "expected prefix");
byte index = read_u8<false>(pc_ + 1, "expected index"); byte index = read_u8<Decoder::kNoValidate>(pc_ + 1, "expected index");
return static_cast<WasmOpcode>(prefix << 8 | index); return static_cast<WasmOpcode>(prefix << 8 | index);
} }
}; };
......
...@@ -1177,7 +1177,7 @@ class ModuleDecoderImpl : public Decoder { ...@@ -1177,7 +1177,7 @@ class ModuleDecoderImpl : public Decoder {
unsigned len = 0; unsigned len = 0;
switch (opcode) { switch (opcode) {
case kExprGetGlobal: { case kExprGetGlobal: {
GlobalIndexOperand<true> operand(this, pc() - 1); GlobalIndexOperand<Decoder::kValidate> operand(this, pc() - 1);
if (module->globals.size() <= operand.index) { if (module->globals.size() <= operand.index) {
error("global index is out of bounds"); error("global index is out of bounds");
expr.kind = WasmInitExpr::kNone; expr.kind = WasmInitExpr::kNone;
...@@ -1199,28 +1199,28 @@ class ModuleDecoderImpl : public Decoder { ...@@ -1199,28 +1199,28 @@ class ModuleDecoderImpl : public Decoder {
break; break;
} }
case kExprI32Const: { case kExprI32Const: {
ImmI32Operand<true> operand(this, pc() - 1); ImmI32Operand<Decoder::kValidate> operand(this, pc() - 1);
expr.kind = WasmInitExpr::kI32Const; expr.kind = WasmInitExpr::kI32Const;
expr.val.i32_const = operand.value; expr.val.i32_const = operand.value;
len = operand.length; len = operand.length;
break; break;
} }
case kExprF32Const: { case kExprF32Const: {
ImmF32Operand<true> operand(this, pc() - 1); ImmF32Operand<Decoder::kValidate> operand(this, pc() - 1);
expr.kind = WasmInitExpr::kF32Const; expr.kind = WasmInitExpr::kF32Const;
expr.val.f32_const = operand.value; expr.val.f32_const = operand.value;
len = operand.length; len = operand.length;
break; break;
} }
case kExprI64Const: { case kExprI64Const: {
ImmI64Operand<true> operand(this, pc() - 1); ImmI64Operand<Decoder::kValidate> operand(this, pc() - 1);
expr.kind = WasmInitExpr::kI64Const; expr.kind = WasmInitExpr::kI64Const;
expr.val.i64_const = operand.value; expr.val.i64_const = operand.value;
len = operand.length; len = operand.length;
break; break;
} }
case kExprF64Const: { case kExprF64Const: {
ImmF64Operand<true> operand(this, pc() - 1); ImmF64Operand<Decoder::kValidate> operand(this, pc() - 1);
expr.kind = WasmInitExpr::kF64Const; expr.kind = WasmInitExpr::kF64Const;
expr.val.f64_const = operand.value; expr.val.f64_const = operand.value;
len = operand.length; len = operand.length;
......
This diff is collapsed.
...@@ -101,7 +101,7 @@ void PrintWasmText(const WasmModule* module, const ModuleWireBytes& wire_bytes, ...@@ -101,7 +101,7 @@ void PrintWasmText(const WasmModule* module, const ModuleWireBytes& wire_bytes,
case kExprIf: case kExprIf:
case kExprBlock: case kExprBlock:
case kExprTry: { case kExprTry: {
BlockTypeOperand<false> operand(&i, i.pc()); BlockTypeOperand<Decoder::kNoValidate> operand(&i, i.pc());
os << WasmOpcodes::OpcodeName(opcode); os << WasmOpcodes::OpcodeName(opcode);
if (operand.type == kWasmVar) { if (operand.type == kWasmVar) {
os << " (type " << operand.sig_index << ")"; os << " (type " << operand.sig_index << ")";
...@@ -113,7 +113,7 @@ void PrintWasmText(const WasmModule* module, const ModuleWireBytes& wire_bytes, ...@@ -113,7 +113,7 @@ void PrintWasmText(const WasmModule* module, const ModuleWireBytes& wire_bytes,
} }
case kExprBr: case kExprBr:
case kExprBrIf: { case kExprBrIf: {
BreakDepthOperand<false> operand(&i, i.pc()); BreakDepthOperand<Decoder::kNoValidate> operand(&i, i.pc());
os << WasmOpcodes::OpcodeName(opcode) << ' ' << operand.depth; os << WasmOpcodes::OpcodeName(opcode) << ' ' << operand.depth;
break; break;
} }
...@@ -125,45 +125,45 @@ void PrintWasmText(const WasmModule* module, const ModuleWireBytes& wire_bytes, ...@@ -125,45 +125,45 @@ void PrintWasmText(const WasmModule* module, const ModuleWireBytes& wire_bytes,
os << "end"; os << "end";
break; break;
case kExprBrTable: { case kExprBrTable: {
BranchTableOperand<false> operand(&i, i.pc()); BranchTableOperand<Decoder::kNoValidate> operand(&i, i.pc());
BranchTableIterator<false> iterator(&i, operand); BranchTableIterator<Decoder::kNoValidate> iterator(&i, operand);
os << "br_table"; os << "br_table";
while (iterator.has_next()) os << ' ' << iterator.next(); while (iterator.has_next()) os << ' ' << iterator.next();
break; break;
} }
case kExprCallIndirect: { case kExprCallIndirect: {
CallIndirectOperand<false> operand(&i, i.pc()); CallIndirectOperand<Decoder::kNoValidate> operand(&i, i.pc());
DCHECK_EQ(0, operand.table_index); DCHECK_EQ(0, operand.table_index);
os << "call_indirect " << operand.index; os << "call_indirect " << operand.index;
break; break;
} }
case kExprCallFunction: { case kExprCallFunction: {
CallFunctionOperand<false> operand(&i, i.pc()); CallFunctionOperand<Decoder::kNoValidate> operand(&i, i.pc());
os << "call " << operand.index; os << "call " << operand.index;
break; break;
} }
case kExprGetLocal: case kExprGetLocal:
case kExprSetLocal: case kExprSetLocal:
case kExprTeeLocal: { case kExprTeeLocal: {
LocalIndexOperand<false> operand(&i, i.pc()); LocalIndexOperand<Decoder::kNoValidate> operand(&i, i.pc());
os << WasmOpcodes::OpcodeName(opcode) << ' ' << operand.index; os << WasmOpcodes::OpcodeName(opcode) << ' ' << operand.index;
break; break;
} }
case kExprThrow: case kExprThrow:
case kExprCatch: { case kExprCatch: {
ExceptionIndexOperand<false> operand(&i, i.pc()); ExceptionIndexOperand<Decoder::kNoValidate> operand(&i, i.pc());
os << WasmOpcodes::OpcodeName(opcode) << ' ' << operand.index; os << WasmOpcodes::OpcodeName(opcode) << ' ' << operand.index;
break; break;
} }
case kExprGetGlobal: case kExprGetGlobal:
case kExprSetGlobal: { case kExprSetGlobal: {
GlobalIndexOperand<false> operand(&i, i.pc()); GlobalIndexOperand<Decoder::kNoValidate> operand(&i, i.pc());
os << WasmOpcodes::OpcodeName(opcode) << ' ' << operand.index; os << WasmOpcodes::OpcodeName(opcode) << ' ' << operand.index;
break; break;
} }
#define CASE_CONST(type, str, cast_type) \ #define CASE_CONST(type, str, cast_type) \
case kExpr##type##Const: { \ case kExpr##type##Const: { \
Imm##type##Operand<false> operand(&i, i.pc()); \ Imm##type##Operand<Decoder::kNoValidate> operand(&i, i.pc()); \
os << #str ".const " << static_cast<cast_type>(operand.value); \ os << #str ".const " << static_cast<cast_type>(operand.value); \
break; \ break; \
} }
...@@ -176,7 +176,8 @@ void PrintWasmText(const WasmModule* module, const ModuleWireBytes& wire_bytes, ...@@ -176,7 +176,8 @@ void PrintWasmText(const WasmModule* module, const ModuleWireBytes& wire_bytes,
#define CASE_OPCODE(opcode, _, __) case kExpr##opcode: #define CASE_OPCODE(opcode, _, __) case kExpr##opcode:
FOREACH_LOAD_MEM_OPCODE(CASE_OPCODE) FOREACH_LOAD_MEM_OPCODE(CASE_OPCODE)
FOREACH_STORE_MEM_OPCODE(CASE_OPCODE) { FOREACH_STORE_MEM_OPCODE(CASE_OPCODE) {
MemoryAccessOperand<false> operand(&i, i.pc(), kMaxUInt32); MemoryAccessOperand<Decoder::kNoValidate> operand(&i, i.pc(),
kMaxUInt32);
os << WasmOpcodes::OpcodeName(opcode) << " offset=" << operand.offset os << WasmOpcodes::OpcodeName(opcode) << " offset=" << operand.offset
<< " align=" << (1ULL << operand.alignment); << " align=" << (1ULL << operand.alignment);
break; break;
...@@ -196,7 +197,8 @@ void PrintWasmText(const WasmModule* module, const ModuleWireBytes& wire_bytes, ...@@ -196,7 +197,8 @@ void PrintWasmText(const WasmModule* module, const ModuleWireBytes& wire_bytes,
WasmOpcode atomic_opcode = i.prefixed_opcode(); WasmOpcode atomic_opcode = i.prefixed_opcode();
switch (atomic_opcode) { switch (atomic_opcode) {
FOREACH_ATOMIC_OPCODE(CASE_OPCODE) { FOREACH_ATOMIC_OPCODE(CASE_OPCODE) {
MemoryAccessOperand<false> operand(&i, i.pc(), kMaxUInt32); MemoryAccessOperand<Decoder::kNoValidate> operand(&i, i.pc(),
kMaxUInt32);
os << WasmOpcodes::OpcodeName(atomic_opcode) os << WasmOpcodes::OpcodeName(atomic_opcode)
<< " offset=" << operand.offset << " offset=" << operand.offset
<< " align=" << (1ULL << operand.alignment); << " align=" << (1ULL << operand.alignment);
......
...@@ -24,8 +24,9 @@ class DecoderTest : public TestWithZone { ...@@ -24,8 +24,9 @@ class DecoderTest : public TestWithZone {
const byte data[] = {__VA_ARGS__}; \ const byte data[] = {__VA_ARGS__}; \
decoder.Reset(data, data + sizeof(data)); \ decoder.Reset(data, data + sizeof(data)); \
unsigned length; \ unsigned length; \
EXPECT_EQ(static_cast<uint32_t>(expected), \ EXPECT_EQ( \
decoder.read_u32v<true>(decoder.start(), &length)); \ static_cast<uint32_t>(expected), \
decoder.read_u32v<Decoder::kValidate>(decoder.start(), &length)); \
EXPECT_EQ(static_cast<unsigned>(expected_length), length); \ EXPECT_EQ(static_cast<unsigned>(expected_length), length); \
EXPECT_EQ(data, decoder.pc()); \ EXPECT_EQ(data, decoder.pc()); \
EXPECT_TRUE(decoder.ok()); \ EXPECT_TRUE(decoder.ok()); \
...@@ -38,7 +39,8 @@ class DecoderTest : public TestWithZone { ...@@ -38,7 +39,8 @@ class DecoderTest : public TestWithZone {
const byte data[] = {__VA_ARGS__}; \ const byte data[] = {__VA_ARGS__}; \
decoder.Reset(data, data + sizeof(data)); \ decoder.Reset(data, data + sizeof(data)); \
unsigned length; \ unsigned length; \
EXPECT_EQ(expected, decoder.read_i32v<true>(decoder.start(), &length)); \ EXPECT_EQ(expected, decoder.read_i32v<Decoder::kValidate>(decoder.start(), \
&length)); \
EXPECT_EQ(static_cast<unsigned>(expected_length), length); \ EXPECT_EQ(static_cast<unsigned>(expected_length), length); \
EXPECT_EQ(data, decoder.pc()); \ EXPECT_EQ(data, decoder.pc()); \
EXPECT_TRUE(decoder.ok()); \ EXPECT_TRUE(decoder.ok()); \
...@@ -51,8 +53,9 @@ class DecoderTest : public TestWithZone { ...@@ -51,8 +53,9 @@ class DecoderTest : public TestWithZone {
const byte data[] = {__VA_ARGS__}; \ const byte data[] = {__VA_ARGS__}; \
decoder.Reset(data, data + sizeof(data)); \ decoder.Reset(data, data + sizeof(data)); \
unsigned length; \ unsigned length; \
EXPECT_EQ(static_cast<uint64_t>(expected), \ EXPECT_EQ( \
decoder.read_u64v<false>(decoder.start(), &length)); \ static_cast<uint64_t>(expected), \
decoder.read_u64v<Decoder::kValidate>(decoder.start(), &length)); \
EXPECT_EQ(static_cast<unsigned>(expected_length), length); \ EXPECT_EQ(static_cast<unsigned>(expected_length), length); \
} while (false) } while (false)
...@@ -61,7 +64,8 @@ class DecoderTest : public TestWithZone { ...@@ -61,7 +64,8 @@ class DecoderTest : public TestWithZone {
const byte data[] = {__VA_ARGS__}; \ const byte data[] = {__VA_ARGS__}; \
decoder.Reset(data, data + sizeof(data)); \ decoder.Reset(data, data + sizeof(data)); \
unsigned length; \ unsigned length; \
EXPECT_EQ(expected, decoder.read_i64v<false>(decoder.start(), &length)); \ EXPECT_EQ(expected, decoder.read_i64v<Decoder::kValidate>(decoder.start(), \
&length)); \
EXPECT_EQ(static_cast<unsigned>(expected_length), length); \ EXPECT_EQ(static_cast<unsigned>(expected_length), length); \
} while (false) } while (false)
...@@ -374,7 +378,7 @@ TEST_F(DecoderTest, ReadU32v_off_end1) { ...@@ -374,7 +378,7 @@ TEST_F(DecoderTest, ReadU32v_off_end1) {
static const byte data[] = {U32V_1(11)}; static const byte data[] = {U32V_1(11)};
unsigned length = 0; unsigned length = 0;
decoder.Reset(data, data); decoder.Reset(data, data);
decoder.read_u32v<true>(decoder.start(), &length); decoder.read_u32v<Decoder::kValidate>(decoder.start(), &length);
EXPECT_EQ(0u, length); EXPECT_EQ(0u, length);
EXPECT_FALSE(decoder.ok()); EXPECT_FALSE(decoder.ok());
} }
...@@ -384,7 +388,7 @@ TEST_F(DecoderTest, ReadU32v_off_end2) { ...@@ -384,7 +388,7 @@ TEST_F(DecoderTest, ReadU32v_off_end2) {
for (size_t i = 0; i < sizeof(data); i++) { for (size_t i = 0; i < sizeof(data); i++) {
unsigned length = 0; unsigned length = 0;
decoder.Reset(data, data + i); decoder.Reset(data, data + i);
decoder.read_u32v<true>(decoder.start(), &length); decoder.read_u32v<Decoder::kValidate>(decoder.start(), &length);
EXPECT_EQ(i, length); EXPECT_EQ(i, length);
EXPECT_FALSE(decoder.ok()); EXPECT_FALSE(decoder.ok());
} }
...@@ -395,7 +399,7 @@ TEST_F(DecoderTest, ReadU32v_off_end3) { ...@@ -395,7 +399,7 @@ TEST_F(DecoderTest, ReadU32v_off_end3) {
for (size_t i = 0; i < sizeof(data); i++) { for (size_t i = 0; i < sizeof(data); i++) {
unsigned length = 0; unsigned length = 0;
decoder.Reset(data, data + i); decoder.Reset(data, data + i);
decoder.read_u32v<true>(decoder.start(), &length); decoder.read_u32v<Decoder::kValidate>(decoder.start(), &length);
EXPECT_EQ(i, length); EXPECT_EQ(i, length);
EXPECT_FALSE(decoder.ok()); EXPECT_FALSE(decoder.ok());
} }
...@@ -406,7 +410,7 @@ TEST_F(DecoderTest, ReadU32v_off_end4) { ...@@ -406,7 +410,7 @@ TEST_F(DecoderTest, ReadU32v_off_end4) {
for (size_t i = 0; i < sizeof(data); i++) { for (size_t i = 0; i < sizeof(data); i++) {
unsigned length = 0; unsigned length = 0;
decoder.Reset(data, data + i); decoder.Reset(data, data + i);
decoder.read_u32v<true>(decoder.start(), &length); decoder.read_u32v<Decoder::kValidate>(decoder.start(), &length);
EXPECT_EQ(i, length); EXPECT_EQ(i, length);
EXPECT_FALSE(decoder.ok()); EXPECT_FALSE(decoder.ok());
} }
...@@ -417,7 +421,7 @@ TEST_F(DecoderTest, ReadU32v_off_end5) { ...@@ -417,7 +421,7 @@ TEST_F(DecoderTest, ReadU32v_off_end5) {
for (size_t i = 0; i < sizeof(data); i++) { for (size_t i = 0; i < sizeof(data); i++) {
unsigned length = 0; unsigned length = 0;
decoder.Reset(data, data + i); decoder.Reset(data, data + i);
decoder.read_u32v<true>(decoder.start(), &length); decoder.read_u32v<Decoder::kValidate>(decoder.start(), &length);
EXPECT_EQ(i, length); EXPECT_EQ(i, length);
EXPECT_FALSE(decoder.ok()); EXPECT_FALSE(decoder.ok());
} }
...@@ -429,7 +433,7 @@ TEST_F(DecoderTest, ReadU32v_extra_bits) { ...@@ -429,7 +433,7 @@ TEST_F(DecoderTest, ReadU32v_extra_bits) {
data[4] = static_cast<byte>(i << 4); data[4] = static_cast<byte>(i << 4);
unsigned length = 0; unsigned length = 0;
decoder.Reset(data, data + sizeof(data)); decoder.Reset(data, data + sizeof(data));
decoder.read_u32v<true>(decoder.start(), &length); decoder.read_u32v<Decoder::kValidate>(decoder.start(), &length);
EXPECT_EQ(5u, length); EXPECT_EQ(5u, length);
EXPECT_FALSE(decoder.ok()); EXPECT_FALSE(decoder.ok());
} }
...@@ -440,7 +444,7 @@ TEST_F(DecoderTest, ReadI32v_extra_bits_negative) { ...@@ -440,7 +444,7 @@ TEST_F(DecoderTest, ReadI32v_extra_bits_negative) {
unsigned length = 0; unsigned length = 0;
byte data[] = {0xff, 0xff, 0xff, 0xff, 0x7f}; byte data[] = {0xff, 0xff, 0xff, 0xff, 0x7f};
decoder.Reset(data, data + sizeof(data)); decoder.Reset(data, data + sizeof(data));
decoder.read_i32v<true>(decoder.start(), &length); decoder.read_i32v<Decoder::kValidate>(decoder.start(), &length);
EXPECT_EQ(5u, length); EXPECT_EQ(5u, length);
EXPECT_TRUE(decoder.ok()); EXPECT_TRUE(decoder.ok());
} }
...@@ -450,7 +454,7 @@ TEST_F(DecoderTest, ReadI32v_extra_bits_positive) { ...@@ -450,7 +454,7 @@ TEST_F(DecoderTest, ReadI32v_extra_bits_positive) {
unsigned length = 0; unsigned length = 0;
byte data[] = {0x80, 0x80, 0x80, 0x80, 0x77}; byte data[] = {0x80, 0x80, 0x80, 0x80, 0x77};
decoder.Reset(data, data + sizeof(data)); decoder.Reset(data, data + sizeof(data));
decoder.read_i32v<true>(decoder.start(), &length); decoder.read_i32v<Decoder::kValidate>(decoder.start(), &length);
EXPECT_EQ(5u, length); EXPECT_EQ(5u, length);
EXPECT_FALSE(decoder.ok()); EXPECT_FALSE(decoder.ok());
} }
...@@ -485,7 +489,7 @@ TEST_F(DecoderTest, ReadU32v_Bits) { ...@@ -485,7 +489,7 @@ TEST_F(DecoderTest, ReadU32v_Bits) {
for (unsigned limit = 0; limit <= kMaxSize; limit++) { for (unsigned limit = 0; limit <= kMaxSize; limit++) {
decoder.Reset(data, data + limit); decoder.Reset(data, data + limit);
unsigned rlen; unsigned rlen;
uint32_t result = decoder.read_u32v<true>(data, &rlen); uint32_t result = decoder.read_u32v<Decoder::kValidate>(data, &rlen);
if (limit < length) { if (limit < length) {
EXPECT_FALSE(decoder.ok()); EXPECT_FALSE(decoder.ok());
} else { } else {
...@@ -541,7 +545,7 @@ TEST_F(DecoderTest, ReadU64v_PowerOf2) { ...@@ -541,7 +545,7 @@ TEST_F(DecoderTest, ReadU64v_PowerOf2) {
for (unsigned limit = 0; limit <= kMaxSize; limit++) { for (unsigned limit = 0; limit <= kMaxSize; limit++) {
decoder.Reset(data, data + limit); decoder.Reset(data, data + limit);
unsigned length; unsigned length;
uint64_t result = decoder.read_u64v<true>(data, &length); uint64_t result = decoder.read_u64v<Decoder::kValidate>(data, &length);
if (limit <= index) { if (limit <= index) {
EXPECT_FALSE(decoder.ok()); EXPECT_FALSE(decoder.ok());
} else { } else {
...@@ -582,7 +586,7 @@ TEST_F(DecoderTest, ReadU64v_Bits) { ...@@ -582,7 +586,7 @@ TEST_F(DecoderTest, ReadU64v_Bits) {
for (unsigned limit = 0; limit <= kMaxSize; limit++) { for (unsigned limit = 0; limit <= kMaxSize; limit++) {
decoder.Reset(data, data + limit); decoder.Reset(data, data + limit);
unsigned rlen; unsigned rlen;
uint64_t result = decoder.read_u64v<true>(data, &rlen); uint64_t result = decoder.read_u64v<Decoder::kValidate>(data, &rlen);
if (limit < length) { if (limit < length) {
EXPECT_FALSE(decoder.ok()); EXPECT_FALSE(decoder.ok());
} else { } else {
...@@ -624,7 +628,7 @@ TEST_F(DecoderTest, ReadI64v_Bits) { ...@@ -624,7 +628,7 @@ TEST_F(DecoderTest, ReadI64v_Bits) {
for (unsigned limit = 0; limit <= kMaxSize; limit++) { for (unsigned limit = 0; limit <= kMaxSize; limit++) {
decoder.Reset(data, data + limit); decoder.Reset(data, data + limit);
unsigned rlen; unsigned rlen;
int64_t result = decoder.read_i64v<true>(data, &rlen); int64_t result = decoder.read_i64v<Decoder::kValidate>(data, &rlen);
if (limit < length) { if (limit < length) {
EXPECT_FALSE(decoder.ok()); EXPECT_FALSE(decoder.ok());
} else { } else {
...@@ -643,7 +647,7 @@ TEST_F(DecoderTest, ReadU64v_extra_bits) { ...@@ -643,7 +647,7 @@ TEST_F(DecoderTest, ReadU64v_extra_bits) {
data[9] = static_cast<byte>(i << 1); data[9] = static_cast<byte>(i << 1);
unsigned length = 0; unsigned length = 0;
decoder.Reset(data, data + sizeof(data)); decoder.Reset(data, data + sizeof(data));
decoder.read_u64v<true>(decoder.start(), &length); decoder.read_u64v<Decoder::kValidate>(decoder.start(), &length);
EXPECT_EQ(10u, length); EXPECT_EQ(10u, length);
EXPECT_FALSE(decoder.ok()); EXPECT_FALSE(decoder.ok());
} }
...@@ -654,7 +658,7 @@ TEST_F(DecoderTest, ReadI64v_extra_bits_negative) { ...@@ -654,7 +658,7 @@ TEST_F(DecoderTest, ReadI64v_extra_bits_negative) {
unsigned length = 0; unsigned length = 0;
byte data[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f}; byte data[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f};
decoder.Reset(data, data + sizeof(data)); decoder.Reset(data, data + sizeof(data));
decoder.read_i64v<true>(decoder.start(), &length); decoder.read_i64v<Decoder::kValidate>(decoder.start(), &length);
EXPECT_EQ(10u, length); EXPECT_EQ(10u, length);
EXPECT_TRUE(decoder.ok()); EXPECT_TRUE(decoder.ok());
} }
...@@ -664,7 +668,7 @@ TEST_F(DecoderTest, ReadI64v_extra_bits_positive) { ...@@ -664,7 +668,7 @@ TEST_F(DecoderTest, ReadI64v_extra_bits_positive) {
unsigned length = 0; unsigned length = 0;
byte data[] = {0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x77}; byte data[] = {0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x77};
decoder.Reset(data, data + sizeof(data)); decoder.Reset(data, data + sizeof(data));
decoder.read_i64v<true>(decoder.start(), &length); decoder.read_i64v<Decoder::kValidate>(decoder.start(), &length);
EXPECT_EQ(10u, length); EXPECT_EQ(10u, length);
EXPECT_FALSE(decoder.ok()); EXPECT_FALSE(decoder.ok());
} }
......
...@@ -2533,15 +2533,15 @@ class BranchTableIteratorTest : public TestWithZone { ...@@ -2533,15 +2533,15 @@ class BranchTableIteratorTest : public TestWithZone {
BranchTableIteratorTest() : TestWithZone() {} BranchTableIteratorTest() : TestWithZone() {}
void CheckBrTableSize(const byte* start, const byte* end) { void CheckBrTableSize(const byte* start, const byte* end) {
Decoder decoder(start, end); Decoder decoder(start, end);
BranchTableOperand<true> operand(&decoder, start); BranchTableOperand<Decoder::kValidate> operand(&decoder, start);
BranchTableIterator<true> iterator(&decoder, operand); BranchTableIterator<Decoder::kValidate> iterator(&decoder, operand);
EXPECT_EQ(end - start - 1u, iterator.length()); EXPECT_EQ(end - start - 1u, iterator.length());
EXPECT_TRUE(decoder.ok()); EXPECT_TRUE(decoder.ok());
} }
void CheckBrTableError(const byte* start, const byte* end) { void CheckBrTableError(const byte* start, const byte* end) {
Decoder decoder(start, end); Decoder decoder(start, end);
BranchTableOperand<true> operand(&decoder, start); BranchTableOperand<Decoder::kValidate> operand(&decoder, start);
BranchTableIterator<true> iterator(&decoder, operand); BranchTableIterator<Decoder::kValidate> iterator(&decoder, operand);
iterator.length(); iterator.length();
EXPECT_FALSE(decoder.ok()); EXPECT_FALSE(decoder.ok());
} }
......
...@@ -98,7 +98,7 @@ TEST_F(LEBHelperTest, sizeof_i32v) { ...@@ -98,7 +98,7 @@ TEST_F(LEBHelperTest, sizeof_i32v) {
static_cast<size_t>(ptr - buffer)); \ static_cast<size_t>(ptr - buffer)); \
Decoder decoder(buffer, buffer + kSize); \ Decoder decoder(buffer, buffer + kSize); \
unsigned length = 0; \ unsigned length = 0; \
ctype result = decoder.read_##name<false>(buffer, &length); \ ctype result = decoder.read_##name<Decoder::kNoValidate>(buffer, &length); \
EXPECT_EQ(val, result); \ EXPECT_EQ(val, result); \
EXPECT_EQ(LEBHelper::sizeof_##name(val), static_cast<size_t>(length)); \ EXPECT_EQ(LEBHelper::sizeof_##name(val), static_cast<size_t>(length)); \
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment