diff options
Diffstat (limited to 'deps/v8/test/fuzzer/wasm-compile.cc')
-rw-r--r-- | deps/v8/test/fuzzer/wasm-compile.cc | 167 |
1 files changed, 83 insertions, 84 deletions
diff --git a/deps/v8/test/fuzzer/wasm-compile.cc b/deps/v8/test/fuzzer/wasm-compile.cc index 6804cfa5c9..663ef33a94 100644 --- a/deps/v8/test/fuzzer/wasm-compile.cc +++ b/deps/v8/test/fuzzer/wasm-compile.cc @@ -122,7 +122,7 @@ class WasmGenerator { : gen_(gen), emit_end_(emit_end) { gen->blocks_.emplace_back(br_types.begin(), br_types.end()); if (param_types.size() == 0 && result_types.size() == 0) { - gen->builder_->EmitWithU8(block_type, kWasmStmt.value_type_code()); + gen->builder_->EmitWithU8(block_type, kWasmVoid.value_type_code()); return; } if (param_types.size() == 0 && result_types.size() == 1) { @@ -135,11 +135,11 @@ class WasmGenerator { FunctionSig::Builder builder(zone, result_types.size(), param_types.size()); for (auto& type : param_types) { - DCHECK_NE(type, kWasmStmt); + DCHECK_NE(type, kWasmVoid); builder.AddParam(type); } for (auto& type : result_types) { - DCHECK_NE(type, kWasmStmt); + DCHECK_NE(type, kWasmVoid); builder.AddReturn(type); } FunctionSig* sig = builder.Build(); @@ -199,10 +199,10 @@ class WasmGenerator { template <ValueKind T, IfType type> void if_(DataRange* data) { - static_assert(T == kStmt || type == kIfElse, + static_assert(T == kVoid || type == kIfElse, "if without else cannot produce a value"); if_({}, - T == kStmt ? Vector<ValueType>{} : VectorOf({ValueType::Primitive(T)}), + T == kVoid ? Vector<ValueType>{} : VectorOf({ValueType::Primitive(T)}), type, data); } @@ -217,7 +217,7 @@ class WasmGenerator { uint8_t delegate_target = data->get<uint8_t>() % (try_blocks_.size() + 1); bool is_unwind = num_catch == 0 && !has_catch_all && !is_delegate; - Vector<const ValueType> return_type_vec = return_type.kind() == kStmt + Vector<const ValueType> return_type_vec = return_type.kind() == kVoid ? Vector<ValueType>{} : VectorOf(&return_type, 1); BlockScope block_scope(this, kExprTry, {}, return_type_vec, return_type_vec, @@ -293,7 +293,7 @@ class WasmGenerator { kExprBr, static_cast<uint32_t>(blocks_.size()) - 1 - target_block); } - template <ValueKind wanted_type> + template <ValueKind wanted_kind> void br_if(DataRange* data) { // There is always at least the block representing the function body. DCHECK(!blocks_.empty()); @@ -305,9 +305,9 @@ class WasmGenerator { builder_->EmitWithI32V( kExprBrIf, static_cast<uint32_t>(blocks_.size()) - 1 - target_block); ConsumeAndGenerate(break_types, - wanted_type == kStmt + wanted_kind == kVoid ? Vector<ValueType>{} - : VectorOf({ValueType::Primitive(wanted_type)}), + : VectorOf({ValueType::Primitive(wanted_kind)}), data); } @@ -424,13 +424,13 @@ class WasmGenerator { } } - template <WasmOpcode memory_op, ValueKind... arg_types> + template <WasmOpcode memory_op, ValueKind... arg_kinds> void memop(DataRange* data) { const uint8_t align = data->get<uint8_t>() % (max_alignment(memory_op) + 1); const uint32_t offset = data->get<uint32_t>(); // Generate the index and the arguments, if any. - Generate<kI32, arg_types...>(data); + Generate<kI32, arg_kinds...>(data); if (WasmOpcodes::IsPrefixOpcode(static_cast<WasmOpcode>(memory_op >> 8))) { DCHECK(memory_op >> 8 == kAtomicPrefix || memory_op >> 8 == kSimdPrefix); @@ -496,14 +496,14 @@ class WasmGenerator { enum CallDirect : bool { kCallDirect = true, kCallIndirect = false }; - template <ValueKind wanted_type> + template <ValueKind wanted_kind> void call(DataRange* data) { - call(data, ValueType::Primitive(wanted_type), kCallDirect); + call(data, ValueType::Primitive(wanted_kind), kCallDirect); } - template <ValueKind wanted_type> + template <ValueKind wanted_kind> void call_indirect(DataRange* data) { - call(data, ValueType::Primitive(wanted_type), kCallIndirect); + call(data, ValueType::Primitive(wanted_kind), kCallIndirect); } void Convert(ValueType src, ValueType dst) { @@ -536,16 +536,16 @@ class WasmGenerator { void ConvertOrGenerate(ValueType src, ValueType dst, DataRange* data) { if (src == dst) return; - if (src == kWasmStmt && dst != kWasmStmt) { + if (src == kWasmVoid && dst != kWasmVoid) { Generate(dst, data); - } else if (dst == kWasmStmt && src != kWasmStmt) { + } else if (dst == kWasmVoid && src != kWasmVoid) { builder_->Emit(kExprDrop); } else { Convert(src, dst); } } - void call(DataRange* data, ValueType wanted_type, CallDirect call_direct) { + void call(DataRange* data, ValueType wanted_kind, CallDirect call_direct) { uint8_t random_byte = data->get<uint8_t>(); int func_index = random_byte % functions_.size(); uint32_t sig_index = functions_[func_index]; @@ -579,12 +579,12 @@ class WasmGenerator { builder_->EmitByte(0); // Table index. } } - if (sig->return_count() == 0 && wanted_type != kWasmStmt) { + if (sig->return_count() == 0 && wanted_kind != kWasmVoid) { // The call did not generate a value. Thus just generate it here. - Generate(wanted_type, data); + Generate(wanted_kind, data); return; } - if (wanted_type == kWasmStmt) { + if (wanted_kind == kWasmVoid) { // The call did generate values, but we did not want one. for (size_t i = 0; i < sig->return_count(); ++i) { builder_->Emit(kExprDrop); @@ -593,16 +593,16 @@ class WasmGenerator { } auto return_types = VectorOf(sig->returns().begin(), sig->return_count()); auto wanted_types = - VectorOf(&wanted_type, wanted_type == kWasmStmt ? 0 : 1); + VectorOf(&wanted_kind, wanted_kind == kWasmVoid ? 0 : 1); ConsumeAndGenerate(return_types, wanted_types, data); } struct Var { uint32_t index; - ValueType type = kWasmStmt; + ValueType type = kWasmVoid; Var() = default; Var(uint32_t index, ValueType type) : index(index), type(type) {} - bool is_valid() const { return type != kWasmStmt; } + bool is_valid() const { return type != kWasmVoid; } }; Var GetRandomLocal(DataRange* data) { @@ -616,34 +616,34 @@ class WasmGenerator { return {index, type}; } - template <ValueKind wanted_type> + template <ValueKind wanted_kind> void local_op(DataRange* data, WasmOpcode opcode) { Var local = GetRandomLocal(data); // If there are no locals and no parameters, just generate any value (if a // value is needed), or do nothing. if (!local.is_valid()) { - if (wanted_type == kStmt) return; - return Generate<wanted_type>(data); + if (wanted_kind == kVoid) return; + return Generate<wanted_kind>(data); } if (opcode != kExprLocalGet) Generate(local.type, data); builder_->EmitWithU32V(opcode, local.index); - if (wanted_type != kStmt && local.type.kind() != wanted_type) { - Convert(local.type, ValueType::Primitive(wanted_type)); + if (wanted_kind != kVoid && local.type.kind() != wanted_kind) { + Convert(local.type, ValueType::Primitive(wanted_kind)); } } - template <ValueKind wanted_type> + template <ValueKind wanted_kind> void get_local(DataRange* data) { - static_assert(wanted_type != kStmt, "illegal type"); - local_op<wanted_type>(data, kExprLocalGet); + static_assert(wanted_kind != kVoid, "illegal type"); + local_op<wanted_kind>(data, kExprLocalGet); } - void set_local(DataRange* data) { local_op<kStmt>(data, kExprLocalSet); } + void set_local(DataRange* data) { local_op<kVoid>(data, kExprLocalSet); } - template <ValueKind wanted_type> + template <ValueKind wanted_kind> void tee_local(DataRange* data) { - local_op<wanted_type>(data, kExprLocalTee); + local_op<wanted_kind>(data, kExprLocalTee); } template <size_t num_bytes> @@ -669,42 +669,42 @@ class WasmGenerator { return {index, type}; } - template <ValueKind wanted_type> + template <ValueKind wanted_kind> void global_op(DataRange* data) { - constexpr bool is_set = wanted_type == kStmt; + constexpr bool is_set = wanted_kind == kVoid; Var global = GetRandomGlobal(data, is_set); // If there are no globals, just generate any value (if a value is needed), // or do nothing. if (!global.is_valid()) { - if (wanted_type == kStmt) return; - return Generate<wanted_type>(data); + if (wanted_kind == kVoid) return; + return Generate<wanted_kind>(data); } if (is_set) Generate(global.type, data); builder_->EmitWithU32V(is_set ? kExprGlobalSet : kExprGlobalGet, global.index); - if (!is_set && global.type.kind() != wanted_type) { - Convert(global.type, ValueType::Primitive(wanted_type)); + if (!is_set && global.type.kind() != wanted_kind) { + Convert(global.type, ValueType::Primitive(wanted_kind)); } } - template <ValueKind wanted_type> + template <ValueKind wanted_kind> void get_global(DataRange* data) { - static_assert(wanted_type != kStmt, "illegal type"); - global_op<wanted_type>(data); + static_assert(wanted_kind != kVoid, "illegal type"); + global_op<wanted_kind>(data); } - template <ValueKind select_type> + template <ValueKind select_kind> void select_with_type(DataRange* data) { - static_assert(select_type != kStmt, "illegal type for select"); - Generate<select_type, select_type, kI32>(data); + static_assert(select_kind != kVoid, "illegal kind for select"); + Generate<select_kind, select_kind, kI32>(data); // num_types is always 1. uint8_t num_types = 1; builder_->EmitWithU8U8(kExprSelectWithType, num_types, - ValueType::Primitive(select_type).value_type_code()); + ValueType::Primitive(select_kind).value_type_code()); } - void set_global(DataRange* data) { global_op<kStmt>(data); } + void set_global(DataRange* data) { global_op<kVoid>(data); } void throw_or_rethrow(DataRange* data) { bool rethrow = data->get<uint8_t>() % 2; @@ -822,31 +822,31 @@ class WasmGenerator { }; template <> -void WasmGenerator::block<kStmt>(DataRange* data) { +void WasmGenerator::block<kVoid>(DataRange* data) { block({}, {}, data); } template <> -void WasmGenerator::loop<kStmt>(DataRange* data) { +void WasmGenerator::loop<kVoid>(DataRange* data) { loop({}, {}, data); } template <> -void WasmGenerator::Generate<kStmt>(DataRange* data) { +void WasmGenerator::Generate<kVoid>(DataRange* data) { GeneratorRecursionScope rec_scope(this); if (recursion_limit_reached() || data->size() == 0) return; constexpr GenerateFn alternatives[] = { - &WasmGenerator::sequence<kStmt, kStmt>, - &WasmGenerator::sequence<kStmt, kStmt, kStmt, kStmt>, - &WasmGenerator::sequence<kStmt, kStmt, kStmt, kStmt, kStmt, kStmt, kStmt, - kStmt>, - &WasmGenerator::block<kStmt>, - &WasmGenerator::loop<kStmt>, - &WasmGenerator::if_<kStmt, kIf>, - &WasmGenerator::if_<kStmt, kIfElse>, + &WasmGenerator::sequence<kVoid, kVoid>, + &WasmGenerator::sequence<kVoid, kVoid, kVoid, kVoid>, + &WasmGenerator::sequence<kVoid, kVoid, kVoid, kVoid, kVoid, kVoid, kVoid, + kVoid>, + &WasmGenerator::block<kVoid>, + &WasmGenerator::loop<kVoid>, + &WasmGenerator::if_<kVoid, kIf>, + &WasmGenerator::if_<kVoid, kIfElse>, &WasmGenerator::br, - &WasmGenerator::br_if<kStmt>, + &WasmGenerator::br_if<kVoid>, &WasmGenerator::memop<kExprI32StoreMem, kI32>, &WasmGenerator::memop<kExprI32StoreMem8, kI32>, @@ -872,13 +872,13 @@ void WasmGenerator::Generate<kStmt>(DataRange* data) { &WasmGenerator::drop, - &WasmGenerator::call<kStmt>, - &WasmGenerator::call_indirect<kStmt>, + &WasmGenerator::call<kVoid>, + &WasmGenerator::call_indirect<kVoid>, &WasmGenerator::set_local, &WasmGenerator::set_global, &WasmGenerator::throw_or_rethrow, - &WasmGenerator::try_block<kStmt>}; + &WasmGenerator::try_block<kVoid>}; GenerateOneOf(alternatives, data); } @@ -897,9 +897,9 @@ void WasmGenerator::Generate<kI32>(DataRange* data) { &WasmGenerator::i32_const<3>, &WasmGenerator::i32_const<4>, - &WasmGenerator::sequence<kI32, kStmt>, - &WasmGenerator::sequence<kStmt, kI32>, - &WasmGenerator::sequence<kStmt, kI32, kStmt>, + &WasmGenerator::sequence<kI32, kVoid>, + &WasmGenerator::sequence<kVoid, kI32>, + &WasmGenerator::sequence<kVoid, kI32, kVoid>, &WasmGenerator::op<kExprI32Eqz, kI32>, &WasmGenerator::op<kExprI32Eq, kI32, kI32>, @@ -1001,13 +1001,13 @@ void WasmGenerator::Generate<kI32>(DataRange* data) { kI32>, &WasmGenerator::op_with_prefix<kExprV128AnyTrue, kS128>, - &WasmGenerator::op_with_prefix<kExprV8x16AllTrue, kS128>, + &WasmGenerator::op_with_prefix<kExprI8x16AllTrue, kS128>, &WasmGenerator::op_with_prefix<kExprI8x16BitMask, kS128>, - &WasmGenerator::op_with_prefix<kExprV16x8AllTrue, kS128>, + &WasmGenerator::op_with_prefix<kExprI16x8AllTrue, kS128>, &WasmGenerator::op_with_prefix<kExprI16x8BitMask, kS128>, - &WasmGenerator::op_with_prefix<kExprV32x4AllTrue, kS128>, + &WasmGenerator::op_with_prefix<kExprI32x4AllTrue, kS128>, &WasmGenerator::op_with_prefix<kExprI32x4BitMask, kS128>, - &WasmGenerator::op_with_prefix<kExprV64x2AllTrue, kS128>, + &WasmGenerator::op_with_prefix<kExprI64x2AllTrue, kS128>, &WasmGenerator::op_with_prefix<kExprI64x2BitMask, kS128>, &WasmGenerator::simd_lane_op<kExprI8x16ExtractLaneS, 16, kS128>, &WasmGenerator::simd_lane_op<kExprI8x16ExtractLaneU, 16, kS128>, @@ -1049,9 +1049,9 @@ void WasmGenerator::Generate<kI64>(DataRange* data) { &WasmGenerator::i64_const<7>, &WasmGenerator::i64_const<8>, - &WasmGenerator::sequence<kI64, kStmt>, - &WasmGenerator::sequence<kStmt, kI64>, - &WasmGenerator::sequence<kStmt, kI64, kStmt>, + &WasmGenerator::sequence<kI64, kVoid>, + &WasmGenerator::sequence<kVoid, kI64>, + &WasmGenerator::sequence<kVoid, kI64, kVoid>, &WasmGenerator::op<kExprI64Add, kI64, kI64>, &WasmGenerator::op<kExprI64Sub, kI64, kI64>, @@ -1154,9 +1154,9 @@ void WasmGenerator::Generate<kF32>(DataRange* data) { } constexpr GenerateFn alternatives[] = { - &WasmGenerator::sequence<kF32, kStmt>, - &WasmGenerator::sequence<kStmt, kF32>, - &WasmGenerator::sequence<kStmt, kF32, kStmt>, + &WasmGenerator::sequence<kF32, kVoid>, + &WasmGenerator::sequence<kVoid, kF32>, + &WasmGenerator::sequence<kVoid, kF32, kVoid>, &WasmGenerator::op<kExprF32Abs, kF32>, &WasmGenerator::op<kExprF32Neg, kF32>, @@ -1211,9 +1211,9 @@ void WasmGenerator::Generate<kF64>(DataRange* data) { } constexpr GenerateFn alternatives[] = { - &WasmGenerator::sequence<kF64, kStmt>, - &WasmGenerator::sequence<kStmt, kF64>, - &WasmGenerator::sequence<kStmt, kF64, kStmt>, + &WasmGenerator::sequence<kF64, kVoid>, + &WasmGenerator::sequence<kVoid, kF64>, + &WasmGenerator::sequence<kVoid, kF64, kVoid>, &WasmGenerator::op<kExprF64Abs, kF64>, &WasmGenerator::op<kExprF64Neg, kF64>, @@ -1304,7 +1304,6 @@ void WasmGenerator::Generate<kS128>(DataRange* data) { &WasmGenerator::op_with_prefix<kExprI8x16SubSatU, kS128, kS128>, &WasmGenerator::op_with_prefix<kExprI8x16MinS, kS128, kS128>, &WasmGenerator::op_with_prefix<kExprI8x16MinU, kS128, kS128>, - // I8x16Mul is prototyped but not in the proposal, thus omitted here. &WasmGenerator::op_with_prefix<kExprI8x16MaxS, kS128, kS128>, &WasmGenerator::op_with_prefix<kExprI8x16MaxU, kS128, kS128>, &WasmGenerator::op_with_prefix<kExprI8x16RoundingAverageU, kS128, kS128>, @@ -1513,8 +1512,8 @@ void WasmGenerator::grow_memory(DataRange* data) { void WasmGenerator::Generate(ValueType type, DataRange* data) { switch (type.kind()) { - case kStmt: - return Generate<kStmt>(data); + case kVoid: + return Generate<kVoid>(data); case kI32: return Generate<kI32>(data); case kI64: @@ -1555,7 +1554,7 @@ void WasmGenerator::Generate(Vector<const ValueType> types, DataRange* data) { } if (types.size() == 0) { - Generate(kWasmStmt, data); + Generate(kWasmVoid, data); return; } if (types.size() == 1) { |