Commit 7e5b7ad1 authored by Jakob Kummerow's avatar Jakob Kummerow Committed by V8 LUCI CQ

[wasm][cleanup] Simplify array.init_from_data

We can simply trap in the runtime, instead of returning sentinels.

Bug: v8:7748, v8:12425
Change-Id: I179c8675fabd3cb730f002ba99ba8cf942a9d4ec
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3669108Reviewed-by: 's avatarManos Koukoutos <manoskouk@chromium.org>
Auto-Submit: Jakob Kummerow <jkummerow@chromium.org>
Commit-Queue: Manos Koukoutos <manoskouk@chromium.org>
Cr-Commit-Position: refs/heads/main@{#80758}
parent cc8b4427
......@@ -5260,21 +5260,9 @@ Node* WasmGraphBuilder::ArrayInitFromData(const wasm::ArrayType* type,
uint32_t data_segment, Node* offset,
Node* length, Node* rtt,
wasm::WasmCodePosition position) {
Node* array = gasm_->CallBuiltin(
return gasm_->CallBuiltin(
Builtin::kWasmArrayInitFromData, Operator::kNoDeopt | Operator::kNoThrow,
gasm_->Uint32Constant(data_segment), offset, length, rtt);
TrapIfTrue(wasm::kTrapArrayTooLarge,
gasm_->TaggedEqual(
array, gasm_->NumberConstant(
wasm::kArrayInitFromDataArrayTooLargeErrorCode)),
position);
TrapIfTrue(
wasm::kTrapDataSegmentOutOfBounds,
gasm_->TaggedEqual(
array, gasm_->NumberConstant(
wasm::kArrayInitFromDataSegmentOutOfBoundsErrorCode)),
position);
return array;
}
Node* WasmGraphBuilder::RttCanon(uint32_t type_index) {
......
......@@ -713,10 +713,6 @@ RUNTIME_FUNCTION(Runtime_WasmArrayCopy) {
return ReadOnlyRoots(isolate).undefined_value();
}
// Returns
// - the new array if the operation succeeds,
// - Smi(0) if the requested array length is too large,
// - Smi(1) if the data segment ran out-of-bounds.
RUNTIME_FUNCTION(Runtime_WasmArrayInitFromData) {
ClearThreadInWasmScope flag_scope(isolate);
HandleScope scope(isolate);
......@@ -730,14 +726,15 @@ RUNTIME_FUNCTION(Runtime_WasmArrayInitFromData) {
uint32_t length_in_bytes = length * element_size;
if (length > static_cast<uint32_t>(WasmArray::MaxLength(element_size))) {
return Smi::FromInt(wasm::kArrayInitFromDataArrayTooLargeErrorCode);
return ThrowWasmError(isolate, MessageTemplate::kWasmTrapArrayTooLarge);
}
// The check above implies no overflow.
DCHECK_EQ(length_in_bytes / element_size, length);
if (!base::IsInBounds<uint32_t>(
offset, length_in_bytes,
instance->data_segment_sizes()[data_segment])) {
return Smi::FromInt(wasm::kArrayInitFromDataSegmentOutOfBoundsErrorCode);
return ThrowWasmError(isolate,
MessageTemplate::kWasmTrapDataSegmentOutOfBounds);
}
Address source = instance->data_segment_starts()[data_segment] + offset;
......
......@@ -3329,6 +3329,8 @@ class LiftoffCompiler {
return values;
}
// Call this after emitting a runtime call that can show up in a stack trace
// (e.g. because it can trap).
void RegisterDebugSideTableEntry(
FullDecoder* decoder,
DebugSideTableBuilder::AssumeSpilling assume_spilling) {
......@@ -5563,20 +5565,11 @@ class LiftoffCompiler {
},
decoder->position());
LiftoffRegister result(kReturnRegister0);
// Reuse the data segment register for error handling.
LiftoffRegister error_smi = data_segment_reg;
LoadSmi(error_smi, kArrayInitFromDataArrayTooLargeErrorCode);
Label* trap_label_array_too_large =
AddOutOfLineTrap(decoder, WasmCode::kThrowWasmTrapArrayTooLarge);
__ emit_cond_jump(kEqual, trap_label_array_too_large, kRef, result.gp(),
error_smi.gp());
LoadSmi(error_smi, kArrayInitFromDataSegmentOutOfBoundsErrorCode);
Label* trap_label_segment_out_of_bounds = AddOutOfLineTrap(
decoder, WasmCode::kThrowWasmTrapDataSegmentOutOfBounds);
__ emit_cond_jump(kEqual, trap_label_segment_out_of_bounds, kRef,
result.gp(), error_smi.gp());
// Pop parameters from the value stack.
__ cache_state()->stack_state.pop_back(3);
RegisterDebugSideTableEntry(decoder, DebugSideTableBuilder::kDidSpill);
LiftoffRegister result(kReturnRegister0);
__ PushRegister(kRef, result);
}
......
......@@ -193,9 +193,6 @@ constexpr int kMaxPolymorphism = 4;
constexpr int32_t kOSRTargetOffset = 5 * kSystemPointerSize;
#endif
constexpr Tagged_t kArrayInitFromDataArrayTooLargeErrorCode = 0;
constexpr Tagged_t kArrayInitFromDataSegmentOutOfBoundsErrorCode = 1;
} // namespace wasm
} // namespace internal
} // namespace v8
......
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