Commit 25830282 authored by Manos Koukoutos's avatar Manos Koukoutos Committed by V8 LUCI CQ

[wasm] Add helper function for CheckForNull

Bug: v8:7748
Change-Id: I78a41e593b668f417f1cc18b24bc61a4b6e098c1
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3135577Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Commit-Queue: Manos Koukoutos <manoskouk@chromium.org>
Cr-Commit-Position: refs/heads/main@{#76627}
parent dd152c48
......@@ -651,21 +651,15 @@ class WasmGraphBuildingInterface {
void CallRef(FullDecoder* decoder, const Value& func_ref,
const FunctionSig* sig, uint32_t sig_index, const Value args[],
Value returns[]) {
CheckForNull null_check = func_ref.type.is_nullable()
? CheckForNull::kWithNullCheck
: CheckForNull::kWithoutNullCheck;
DoCall(decoder, kCallRef, 0, null_check, func_ref.node, sig, sig_index,
args, returns);
DoCall(decoder, kCallRef, 0, NullCheckFor(func_ref.type), func_ref.node,
sig, sig_index, args, returns);
}
void ReturnCallRef(FullDecoder* decoder, const Value& func_ref,
const FunctionSig* sig, uint32_t sig_index,
const Value args[]) {
CheckForNull null_check = func_ref.type.is_nullable()
? CheckForNull::kWithNullCheck
: CheckForNull::kWithoutNullCheck;
DoReturnCall(decoder, kCallRef, 0, null_check, func_ref, sig, sig_index,
args);
DoReturnCall(decoder, kCallRef, 0, NullCheckFor(func_ref.type), func_ref,
sig, sig_index, args);
}
void BrOnNull(FullDecoder* decoder, const Value& ref_object, uint32_t depth) {
......@@ -924,23 +918,17 @@ class WasmGraphBuildingInterface {
void StructGet(FullDecoder* decoder, const Value& struct_object,
const FieldImmediate<validate>& field, bool is_signed,
Value* result) {
CheckForNull null_check = struct_object.type.is_nullable()
? CheckForNull::kWithNullCheck
: CheckForNull::kWithoutNullCheck;
result->node = builder_->StructGet(
struct_object.node, field.struct_imm.struct_type, field.field_imm.index,
null_check, is_signed, decoder->position());
NullCheckFor(struct_object.type), is_signed, decoder->position());
}
void StructSet(FullDecoder* decoder, const Value& struct_object,
const FieldImmediate<validate>& field,
const Value& field_value) {
CheckForNull null_check = struct_object.type.is_nullable()
? CheckForNull::kWithNullCheck
: CheckForNull::kWithoutNullCheck;
builder_->StructSet(struct_object.node, field.struct_imm.struct_type,
field.field_imm.index, field_value.node, null_check,
decoder->position());
field.field_imm.index, field_value.node,
NullCheckFor(struct_object.type), decoder->position());
}
void ArrayNewWithRtt(FullDecoder* decoder,
......@@ -969,30 +957,21 @@ class WasmGraphBuildingInterface {
void ArrayGet(FullDecoder* decoder, const Value& array_obj,
const ArrayIndexImmediate<validate>& imm, const Value& index,
bool is_signed, Value* result) {
CheckForNull null_check = array_obj.type.is_nullable()
? CheckForNull::kWithNullCheck
: CheckForNull::kWithoutNullCheck;
result->node =
builder_->ArrayGet(array_obj.node, imm.array_type, index.node,
null_check, is_signed, decoder->position());
result->node = builder_->ArrayGet(array_obj.node, imm.array_type,
index.node, NullCheckFor(array_obj.type),
is_signed, decoder->position());
}
void ArraySet(FullDecoder* decoder, const Value& array_obj,
const ArrayIndexImmediate<validate>& imm, const Value& index,
const Value& value) {
CheckForNull null_check = array_obj.type.is_nullable()
? CheckForNull::kWithNullCheck
: CheckForNull::kWithoutNullCheck;
builder_->ArraySet(array_obj.node, imm.array_type, index.node, value.node,
null_check, decoder->position());
NullCheckFor(array_obj.type), decoder->position());
}
void ArrayLen(FullDecoder* decoder, const Value& array_obj, Value* result) {
CheckForNull null_check = array_obj.type.is_nullable()
? CheckForNull::kWithNullCheck
: CheckForNull::kWithoutNullCheck;
result->node =
builder_->ArrayLen(array_obj.node, null_check, decoder->position());
result->node = builder_->ArrayLen(
array_obj.node, NullCheckFor(array_obj.type), decoder->position());
}
void ArrayCopy(FullDecoder* decoder, const Value& dst, const Value& dst_index,
......@@ -1598,6 +1577,12 @@ class WasmGraphBuildingInterface {
builder_->TerminateThrow(effect(), control());
}
}
CheckForNull NullCheckFor(ValueType type) {
DCHECK(type.is_object_reference());
return type.is_nullable() ? CheckForNull::kWithNullCheck
: CheckForNull::kWithoutNullCheck;
}
};
} // namespace
......
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