diff --git a/cranelift/wasm/src/func_translator.rs b/cranelift/wasm/src/func_translator.rs index a7dbf0820a..cc61b28c9b 100644 --- a/cranelift/wasm/src/func_translator.rs +++ b/cranelift/wasm/src/func_translator.rs @@ -196,6 +196,7 @@ fn declare_locals( let constant_handle = builder.func.dfg.constants.insert([0; 16].to_vec().into()); builder.ins().vconst(ir::types::I8X16, constant_handle) } + NullRef => builder.ins().null(environ.reference_type()), AnyRef => builder.ins().null(environ.reference_type()), AnyFunc => builder.ins().null(environ.reference_type()), ty => return Err(wasm_unsupported!("unsupported local type {:?}", ty)), diff --git a/cranelift/wasm/src/translation_utils.rs b/cranelift/wasm/src/translation_utils.rs index 9d38d9dbb6..d431c13f29 100644 --- a/cranelift/wasm/src/translation_utils.rs +++ b/cranelift/wasm/src/translation_utils.rs @@ -131,7 +131,9 @@ pub fn type_to_type( wasmparser::Type::F32 => Ok(ir::types::F32), wasmparser::Type::F64 => Ok(ir::types::F64), wasmparser::Type::V128 => Ok(ir::types::I8X16), - wasmparser::Type::AnyRef | wasmparser::Type::AnyFunc => Ok(environ.reference_type()), + wasmparser::Type::AnyRef | wasmparser::Type::AnyFunc | wasmparser::Type::NullRef => { + Ok(environ.reference_type()) + } ty => Err(wasm_unsupported!("type_to_type: wasm type {:?}", ty)), } } @@ -171,6 +173,7 @@ pub fn blocktype_params_results( wasmparser::Type::V128 => (&[], &[wasmparser::Type::V128]), wasmparser::Type::AnyRef => (&[], &[wasmparser::Type::AnyRef]), wasmparser::Type::AnyFunc => (&[], &[wasmparser::Type::AnyFunc]), + wasmparser::Type::NullRef => (&[], &[wasmparser::Type::NullRef]), wasmparser::Type::EmptyBlockType => (&[], &[]), ty => return Err(wasm_unsupported!("blocktype_params_results: type {:?}", ty)), }, @@ -203,7 +206,7 @@ pub fn ebb_with_params( wasmparser::Type::F64 => { builder.append_ebb_param(ebb, ir::types::F64); } - wasmparser::Type::AnyRef | wasmparser::Type::AnyFunc => { + wasmparser::Type::AnyRef | wasmparser::Type::AnyFunc | wasmparser::Type::NullRef => { builder.append_ebb_param(ebb, environ.reference_type()); } wasmparser::Type::V128 => { diff --git a/cranelift/wasmtests/nullref.wat b/cranelift/wasmtests/nullref.wat new file mode 100644 index 0000000000..86714a2b6e --- /dev/null +++ b/cranelift/wasmtests/nullref.wat @@ -0,0 +1,11 @@ +(module + (func (result nullref) + ref.null + ) + + (func (result nullref) + (block (result nullref) + ref.null + ) + ) +)