Commit fed595d9 authored by Matthias Liedtke's avatar Matthias Liedtke Committed by V8 LUCI CQ

[fuzzer][wasm-gc] Add types nullfuncref, nullexternref and nullref

nullfuncref = ref null nofunc
nullexternref = ref null noextern
nullref = ref null none

Bug: v8:7748
Change-Id: Ia54ac52c81bde4315e2d6819cff032cb739216c7
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3820064
Commit-Queue: Matthias Liedtke <mliedtke@chromium.org>
Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Auto-Submit: Matthias Liedtke <mliedtke@chromium.org>
Cr-Commit-Position: refs/heads/main@{#82425}
parent 937b5d40
...@@ -6337,6 +6337,10 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder { ...@@ -6337,6 +6337,10 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder {
gasm_->Bind(&done); gasm_->Bind(&done);
return done.PhiAt(0); return done.PhiAt(0);
} }
case wasm::HeapType::kNone:
case wasm::HeapType::kNoFunc:
case wasm::HeapType::kNoExtern:
UNREACHABLE();
default: default:
DCHECK(type.has_index()); DCHECK(type.has_index());
if (module_->has_signature(type.ref_index())) { if (module_->has_signature(type.ref_index())) {
...@@ -6540,6 +6544,10 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder { ...@@ -6540,6 +6544,10 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder {
kLeaveFunctionsAlone); kLeaveFunctionsAlone);
case wasm::HeapType::kString: case wasm::HeapType::kString:
return BuildCheckString(input, js_context, type); return BuildCheckString(input, js_context, type);
case wasm::HeapType::kNone:
case wasm::HeapType::kNoFunc:
case wasm::HeapType::kNoExtern:
UNREACHABLE();
default: default:
if (module_->has_signature(type.ref_index())) { if (module_->has_signature(type.ref_index())) {
BuildCheckValidRefValue(input, js_context, type); BuildCheckValidRefValue(input, js_context, type);
......
...@@ -42,9 +42,18 @@ bool IsJSCompatibleSignature(const FunctionSig* sig, const WasmModule* module, ...@@ -42,9 +42,18 @@ bool IsJSCompatibleSignature(const FunctionSig* sig, const WasmModule* module,
(type.has_index() && !module->has_signature(type.ref_index()))) { (type.has_index() && !module->has_signature(type.ref_index()))) {
return false; return false;
} }
if (type == kWasmStringViewWtf8 || type == kWasmStringViewWtf16 || if (type.is_object_reference()) {
type == kWasmStringViewIter) { switch (type.heap_type().representation()) {
return false; case HeapType::kStringViewWtf8:
case HeapType::kStringViewWtf16:
case HeapType::kStringViewIter:
case HeapType::kNone:
case HeapType::kNoFunc:
case HeapType::kNoExtern:
return false;
default:
break;
}
} }
} }
return true; return true;
......
...@@ -126,7 +126,9 @@ ValueType GetValueTypeHelper(DataRange* data, bool liftoff_as_reference, ...@@ -126,7 +126,9 @@ ValueType GetValueTypeHelper(DataRange* data, bool liftoff_as_reference,
const bool nullable = const bool nullable =
(allow_non_nullable == kAllowNonNullables) ? data->get<bool>() : true; (allow_non_nullable == kAllowNonNullables) ? data->get<bool>() : true;
if (nullable) { if (nullable) {
types.insert(types.end(), {kWasmI31Ref, kWasmFuncRef, kWasmExternRef}); types.insert(types.end(),
{kWasmI31Ref, kWasmFuncRef, kWasmExternRef, kWasmNullRef,
kWasmNullExternRef, kWasmNullFuncRef});
} }
if (include_generics == kIncludeGenerics) { if (include_generics == kIncludeGenerics) {
types.insert(types.end(), {kWasmDataRef, kWasmAnyRef, kWasmEqRef}); types.insert(types.end(), {kWasmDataRef, kWasmAnyRef, kWasmEqRef});
...@@ -2203,11 +2205,15 @@ void WasmGenerator::GenerateRef(HeapType type, DataRange* data, ...@@ -2203,11 +2205,15 @@ void WasmGenerator::GenerateRef(HeapType type, DataRange* data,
return; return;
} }
case HeapType::kExtern: case HeapType::kExtern:
case HeapType::kNoExtern:
case HeapType::kNoFunc:
case HeapType::kNone:
DCHECK(nullability == Nullability::kNullable); DCHECK(nullability == Nullability::kNullable);
ref_null(type, data); ref_null(type, data);
return; return;
default: default:
// Indexed type. // Indexed type.
DCHECK(type.is_index());
DCHECK(liftoff_as_reference_); DCHECK(liftoff_as_reference_);
GenerateOneOf(alternatives_indexed_type, type, data, nullability); GenerateOneOf(alternatives_indexed_type, type, data, nullability);
return; return;
......
...@@ -240,6 +240,12 @@ std::string HeapTypeToJSByteEncoding(HeapType heap_type) { ...@@ -240,6 +240,12 @@ std::string HeapTypeToJSByteEncoding(HeapType heap_type) {
return "kAnyRefCode"; return "kAnyRefCode";
case HeapType::kExtern: case HeapType::kExtern:
return "kExternRefCode"; return "kExternRefCode";
case HeapType::kNone:
return "kNullRefCode";
case HeapType::kNoFunc:
return "kNullFuncRefCode";
case HeapType::kNoExtern:
return "kNullExternRefCode";
case HeapType::kBottom: case HeapType::kBottom:
UNREACHABLE(); UNREACHABLE();
default: default:
...@@ -263,6 +269,12 @@ std::string HeapTypeToConstantName(HeapType heap_type) { ...@@ -263,6 +269,12 @@ std::string HeapTypeToConstantName(HeapType heap_type) {
return "kWasmExternRef"; return "kWasmExternRef";
case HeapType::kAny: case HeapType::kAny:
return "kWasmAnyRef"; return "kWasmAnyRef";
case HeapType::kNone:
return "kWasmNullRef";
case HeapType::kNoFunc:
return "kWasmNullFuncRef";
case HeapType::kNoExtern:
return "kWasmNullExternRef";
case HeapType::kBottom: case HeapType::kBottom:
UNREACHABLE(); UNREACHABLE();
default: default:
......
...@@ -46,6 +46,10 @@ let instance = (() => { ...@@ -46,6 +46,10 @@ let instance = (() => {
eq: kWasmEqRef, eq: kWasmEqRef,
func: kWasmFuncRef, func: kWasmFuncRef,
any: kWasmAnyRef, any: kWasmAnyRef,
extern: kWasmExternRef,
none: kWasmNullRef,
nofunc: kWasmNullFuncRef,
noextern: kWasmNullExternRef,
}; };
for (key in test_types) { for (key in test_types) {
...@@ -144,3 +148,16 @@ assertThrows( ...@@ -144,3 +148,16 @@ assertThrows(
assertThrows( assertThrows(
() => instance.exports.raw_array_id(instance.exports.array_producer()), () => instance.exports.raw_array_id(instance.exports.array_producer()),
TypeError, 'type incompatibility when transforming from/to JS'); TypeError, 'type incompatibility when transforming from/to JS');
// We can roundtrip an extern.
assertEquals(null, instance.exports.extern_id(instance.exports.extern_null()));
// The special null types are not allowed on the boundary from/to JS.
for (const nullType of ["none", "nofunc", "noextern"]) {
assertThrows(
() => instance.exports[`${nullType}_null`](),
TypeError, 'type incompatibility when transforming from/to JS');
assertThrows(
() => instance.exports[`${nullType}_id`](),
TypeError, 'type incompatibility when transforming from/to JS');
}
...@@ -123,8 +123,11 @@ let kWasmExternRef = -0x11; ...@@ -123,8 +123,11 @@ let kWasmExternRef = -0x11;
let kWasmAnyRef = -0x12; let kWasmAnyRef = -0x12;
let kWasmEqRef = -0x13; let kWasmEqRef = -0x13;
let kWasmI31Ref = -0x16; let kWasmI31Ref = -0x16;
let kWasmNullExternRef = -0x17;
let kWasmNullFuncRef = -0x18;
let kWasmDataRef = -0x19; let kWasmDataRef = -0x19;
let kWasmArrayRef = -0x1a; let kWasmArrayRef = -0x1a;
let kWasmNullRef = -0x1b;
let kWasmStringRef = -0x1c; let kWasmStringRef = -0x1c;
let kWasmStringViewWtf8 = -0x1d; let kWasmStringViewWtf8 = -0x1d;
let kWasmStringViewWtf16 = -0x1e; let kWasmStringViewWtf16 = -0x1e;
...@@ -138,8 +141,11 @@ let kExternRefCode = kWasmExternRef & kLeb128Mask; ...@@ -138,8 +141,11 @@ let kExternRefCode = kWasmExternRef & kLeb128Mask;
let kAnyRefCode = kWasmAnyRef & kLeb128Mask; let kAnyRefCode = kWasmAnyRef & kLeb128Mask;
let kEqRefCode = kWasmEqRef & kLeb128Mask; let kEqRefCode = kWasmEqRef & kLeb128Mask;
let kI31RefCode = kWasmI31Ref & kLeb128Mask; let kI31RefCode = kWasmI31Ref & kLeb128Mask;
let kNullExternRefCode = kWasmNullExternRef & kLeb128Mask;
let kNullFuncRefCode = kWasmNullFuncRef & kLeb128Mask;
let kDataRefCode = kWasmDataRef & kLeb128Mask; let kDataRefCode = kWasmDataRef & kLeb128Mask;
let kArrayRefCode = kWasmArrayRef & kLeb128Mask; let kArrayRefCode = kWasmArrayRef & kLeb128Mask;
let kNullRefCode = kWasmNullRef & kLeb128Mask;
let kStringRefCode = kWasmStringRef & kLeb128Mask; let kStringRefCode = kWasmStringRef & kLeb128Mask;
let kStringViewWtf8Code = kWasmStringViewWtf8 & kLeb128Mask; let kStringViewWtf8Code = kWasmStringViewWtf8 & kLeb128Mask;
let kStringViewWtf16Code = kWasmStringViewWtf16 & kLeb128Mask; let kStringViewWtf16Code = kWasmStringViewWtf16 & kLeb128Mask;
......
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