diff --git a/crates/cranelift/src/func_environ.rs b/crates/cranelift/src/func_environ.rs index efe1e5beb682..99ebd0314651 100644 --- a/crates/cranelift/src/func_environ.rs +++ b/crates/cranelift/src/func_environ.rs @@ -494,6 +494,7 @@ impl<'module_environment> cranelift_wasm::FuncEnvironment for FuncEnvironment<'m let reference_type = self.reference_type(WasmType::ExternRef); + builder.ensure_inserted_block(); let continue_block = builder.create_block(); let non_null_elem_block = builder.create_block(); let gc_block = builder.create_block(); @@ -643,6 +644,7 @@ impl<'module_environment> cranelift_wasm::FuncEnvironment for FuncEnvironment<'m // drop the old table element *after* we've replaced it with // the new `value`! + builder.ensure_inserted_block(); let current_block = builder.current_block().unwrap(); let inc_ref_count_block = builder.create_block(); builder.insert_block_after(inc_ref_count_block, current_block); diff --git a/tests/misc_testsuite/reference-types/no-panic.wast b/tests/misc_testsuite/reference-types/no-panic.wast new file mode 100644 index 000000000000..f6318ed6be54 --- /dev/null +++ b/tests/misc_testsuite/reference-types/no-panic.wast @@ -0,0 +1,26 @@ +(module + (func $test (param i32) (result externref) + i32.const 0 + if + else + end + local.get 0 + table.get 0 + ) + (table 4 externref) + (export "test" (func $test)) +) + +(module + (func $test (param i32) + i32.const 0 + if + else + end + local.get 0 + ref.null extern + table.set 0 + ) + (table 4 externref) + (export "test" (func $test)) +)