Skip to content

A lightweight WebAssembly runtime that is fast, secure, and standards-compliant

Migrate more tests to `*.wast` (#15249)

Alex Crichton107a04c41ade
diff --git a/tests/all/component_model.rs b/tests/all/component_model.rs
index 83cb5877dd..420338ea39 100644
--- a/tests/all/component_model.rs
+++ b/tests/all/component_model.rs
@@ -15,7 +15,6 @@ mod call_hook;
mod dynamic;
mod fixed_length_list;
mod func;
-mod handle_table_limit;
mod import;
mod instance;
mod linker;
diff --git a/tests/all/component_model/handle_table_limit.rs b/tests/all/component_model/handle_table_limit.rs
deleted file mode 100644
index b576a659fe..0000000000
--- a/tests/all/component_model/handle_table_limit.rs
+++ /dev/null
@@ -1,274 +0,0 @@
-//! Tests for the store-level cap on the number of simultaneously-live
-//! component-model handles.
-
-#![cfg(not(miri))]
-
-use super::engine;
-use crate::ErrorExt;
-use wasmtime::component::{Component, Linker};
-use wasmtime::{Result, Store};
-
-/// Two instances of one sub-component, each with its own handle table, so the
-/// per-store nature of the cap can be exercised. `sprayN(n)` allocates `n` live
-/// handles; `churnN(n)` allocates and drops one `n` times, staying at one live;
-/// `drop-allN(n)` drops handles `1..=n`, the ones a first `sprayN(n)` returns.
-const COMPONENT: &str = r#"
-(component
- (component $C
- (type $r (resource (rep i32)))
- (core func $new (canon resource.new $r))
- (core func $drop (canon resource.drop $r))
- (core module $m
- (import "" "new" (func $new (param i32) (result i32)))
- (import "" "drop" (func $drop (param i32)))
- (func (export "spray") (param $n i32) (result i32)
- (local $i i32)
- (loop $l
- (if (i32.lt_u (local.get $i) (local.get $n))
- (then
- (drop (call $new (local.get $i)))
- (local.set $i (i32.add (local.get $i) (i32.const 1)))
- (br $l))))
- (local.get $i))
- (func (export "churn") (param $n i32) (result i32)
- (local $i i32)
- (loop $l
- (if (i32.lt_u (local.get $i) (local.get $n))
- (then
- (call $drop (call $new (local.get $i)))
- (local.set $i (i32.add (local.get $i) (i32.const 1)))
- (br $l))))
- (local.get $i))
- (func (export "drop-all") (param $n i32)
- (local $i i32)
- (loop $l
- (if (i32.lt_u (local.get $i) (local.get $n))
- (then
- (local.set $i (i32.add (local.get $i) (i32.const 1)))
- (call $drop (local.get $i))
- (br $l))))))
- (core instance $i (instantiate $m
- (with "" (instance
- (export "new" (func $new))
- (export "drop" (func $drop))))))
- (func (export "spray") (param "n" u32) (result u32)
- (canon lift (core func $i "spray")))
- (func (export "churn") (param "n" u32) (result u32)
- (canon lift (core func $i "churn")))
- (func (export "drop-all") (param "n" u32)
- (canon lift (core func $i "drop-all"))))
-
- (instance $i0 (instantiate $C))
- (export "spray0" (func $i0 "spray"))
- (export "churn0" (func $i0 "churn"))
- (export "drop-all0" (func $i0 "drop-all"))
- (instance $i1 (instantiate $C))
- (export "spray1" (func $i1 "spray"))
- (export "churn1" (func $i1 "churn"))
-)
-"#;
-
-/// The cap is per store, not per table: two instances whose combined (but not
-/// individual) allocations cross the limit. The old per-table `MAX_HANDLE` check
-/// would let this pass.
-#[test]
-fn cap_is_per_store_not_per_table() -> Result<()> {
- let engine = engine();
- let component = Component::new(&engine, COMPONENT)?;
- let linker = Linker::new(&engine);
-
- let mut store = Store::new(&engine, ());
- store.set_max_component_handles(20);
-
- let instance = linker.instantiate(&mut store, &component)?;
- let spray0 = instance.get_typed_func::<(u32,), (u32,)>(&mut store, "spray0")?;
- let spray1 = instance.get_typed_func::<(u32,), (u32,)>(&mut store, "spray1")?;
-
- // 12 is under the limit of 20, so this alone succeeds.
- let (n,) = spray0.call(&mut store, (12,))?;
- assert_eq!(n, 12);
-
- // Another 12 in the second instance's own table trips the shared limit; a
- // per-table cap would allow it.
- spray1
- .call(&mut store, (12,))
- .unwrap_err()
- .assert_contains("store handle limit exceeded");
-
- Ok(())
-}
-
-/// Raising the limit admits a spray a tight limit rejects.
-#[test]
-fn knob_raises_the_limit() -> Result<()> {
- let engine = engine();
- let component = Component::new(&engine, COMPONENT)?;
- let linker = Linker::new(&engine);
-
- // Tight limit: spraying past it traps.
- let mut store = Store::new(&engine, ());
- store.set_max_component_handles(10);
- assert_eq!(store.max_component_handles(), 10);
- let instance = linker.instantiate(&mut store, &component)?;
- let spray0 = instance.get_typed_func::<(u32,), (u32,)>(&mut store, "spray0")?;
- spray0
- .call(&mut store, (50,))
- .unwrap_err()
- .assert_contains("store handle limit exceeded");
-
- // Generous limit: the same spray succeeds.
- let mut store = Store::new(&engine, ());
- store.set_max_component_handles(1_000);
- assert_eq!(store.max_component_handles(), 1_000);
- let instance = linker.instantiate(&mut store, &component)?;
- let spray0 = instance.get_typed_func::<(u32,), (u32,)>(&mut store, "spray0")?;
- let (n,) = spray0.call(&mut store, (50,))?;
- assert_eq!(n, 50);
-
- Ok(())
-}
-
-/// The cap counts table slots, not cumulative allocations: churning well past
-/// the limit succeeds because each dropped handle's slot is reused.
-#[test]
-fn freeing_handles_returns_budget() -> Result<()> {
- let engine = engine();
- let component = Component::new(&engine, COMPONENT)?;
- let linker = Linker::new(&engine);
-
- let mut store = Store::new(&engine, ());
- let limit = 100;
- store.set_max_component_handles(limit);
-
- let instance = linker.instantiate(&mut store, &component)?;
- let churn0 = instance.get_typed_func::<(u32,), (u32,)>(&mut store, "churn0")?;
-
- // Far more allocations than the limit, each dropped, so live count stays low.
- let total = u32::try_from(limit).unwrap() * 100;
- let (n,) = churn0.call(&mut store, (total,))?;
- assert_eq!(n, total);
-
- // The budget is fully available again afterward.
- let spray0 = instance.get_typed_func::<(u32,), (u32,)>(&mut store, "spray0")?;
- let (n,) = spray0.call(&mut store, (50,))?;
- assert_eq!(n, 50);
-
- Ok(())
-}
-
-#[test]
-fn freed_slots_charged() -> Result<()> {
- let engine = engine();
- let component = Component::new(&engine, COMPONENT)?;
- let linker = Linker::new(&engine);
-
- let mut store = Store::new(&engine, ());
- store.set_max_component_handles(20);
-
- let instance = linker.instantiate(&mut store, &component)?;
- let spray0 = instance.get_typed_func::<(u32,), (u32,)>(&mut store, "spray0")?;
- let drop_all0 = instance.get_typed_func::<(u32,), ()>(&mut store, "drop-all0")?;
- let spray1 = instance.get_typed_func::<(u32,), (u32,)>(&mut store, "spray1")?;
-
- // Grow the first instance's table to 15 slots, then free them all.
- spray0.call(&mut store, (15,))?;
- drop_all0.call(&mut store, (15,))?;
-
- // The second instance can't grow its table past the remaining 5.
- spray1
- .call(&mut store, (10,))
- .unwrap_err()
- .assert_contains("store handle limit exceeded");
-
- Ok(())
-}
-
-/// Borrows lent to the resource's owner count against the limit while the
-/// call is active, and return their budget when it returns.
-#[test]
-fn lends_to_owner_count_against_the_limit() -> Result<()> {
- // `$D` defines a resource and `$U` passes a `list<borrow<R>>` of `n` copies
- // of one handle to `$D`'s `take`, `k` times. `$D` receives reps, so no
- // handles are created for the borrows, but each lend still counts against
- // the limit until `take` returns.
- const LEND_COMPONENT: &str = r#"
-(component
- (component $D
- (type $R (resource (rep i32)))
- (core func $new (canon resource.new $R))
- (core module $m
- (import "" "new" (func $new (param i32) (result i32)))
- (memory (export "mem") 1)
- (func (export "realloc") (param i32 i32 i32 i32) (result i32) (i32.const 16))
- (func (export "make") (result i32) (call $new (i32.const 42)))
- (func (export "take") (param i32 i32) (result i32) (local.get 1)))
- (core instance $i (instantiate $m (with "" (instance (export "new" (func $new))))))
- (export $Rx "r" (type $R))
- (func (export "make") (result (own $Rx)) (canon lift (core func $i "make")))
- (func (export "take") (param "xs" (list (borrow $Rx))) (result u32)
- (canon lift (core func $i "take") (memory (core memory $i "mem"))
- (realloc (core func $i "realloc")))))
- (instance $d (instantiate $D))
-
- (component $U
- (import "r" (type $R (sub resource)))
- (import "make" (func $make (result (own $R))))
- (import "take" (func $take (param "xs" (list (borrow $R))) (result u32)))
- (core module $mm (memory (export "mem") 1))
- (core instance $mi (instantiate $mm))
- (core func $make (canon lower (func $make)))
- (core func $take (canon lower (func $take) (memory (core memory $mi "mem"))))
- (core module $m
- (import "" "mem" (memory 1))
- (import "" "make" (func $make (result i32)))
- (import "" "take" (func $take (param i32 i32) (result i32)))
- (func (export "run") (param $n i32) (param $k i32) (result i32)
- (local $h i32) (local $i i32)
- (local.set $h (call $make))
- (loop $l
- (if (i32.lt_u (local.get $i) (local.get $n)) (then
- (i32.store (i32.shl (local.get $i) (i32.const 2)) (local.get $h))
- (local.set $i (i32.add (local.get $i) (i32.const 1)))
- (br $l))))
- (local.set $i (i32.const 0))
- (loop $l
- (if (i32.lt_u (local.get $i) (local.get $k)) (then
- (drop (call $take (i32.const 0) (local.get $n)))
- (local.set $i (i32.add (local.get $i) (i32.const 1)))
- (br $l))))
- (local.get $k)))
- (core instance $i (instantiate $m (with "" (instance
- (export "mem" (memory $mi "mem"))
- (export "make" (func $make)) (export "take" (func $take))))))
- (func (export "run") (param "n" u32) (param "k" u32) (result u32)
- (canon lift (core func $i "run"))))
- (instance $u (instantiate $U (with "r" (type $d "r"))
- (with "make" (func $d "make")) (with "take" (func $d "take"))))
- (export "run" (func $u "run"))
-)
-"#;
- let engine = engine();
- let component = Component::new(&engine, LEND_COMPONENT)?;
- let linker = Linker::new(&engine);
-
- let mut store = Store::new(&engine, ());
- store.set_max_component_handles(20);
- let instance = linker.instantiate(&mut store, &component)?;
- let run = instance.get_typed_func::<(u32, u32), (u32,)>(&mut store, "run")?;
-
- // Ten lends at a time, many times over, fit.
- let (n,) = run.call(&mut store, (10, 100))?;
- assert_eq!(n, 100);
-
- let mut store = Store::new(&engine, ());
- store.set_max_component_handles(20);
- let instance = linker.instantiate(&mut store, &component)?;
- let run = instance.get_typed_func::<(u32, u32), (u32,)>(&mut store, "run")?;
-
- // Fifty lends in one call don't.
- run.call(&mut store, (50, 1))
- .unwrap_err()
- .assert_contains("store handle limit exceeded");
-
- Ok(())
-}
diff --git a/tests/all/debug.rs b/tests/all/debug.rs
index 9f10d4b9b5..10ff7daa87 100644
--- a/tests/all/debug.rs
+++ b/tests/all/debug.rs
@@ -1984,38 +1984,6 @@ async fn take_exception_in_debug_handler() -> Result<()> {
}
}
-#[test]
-#[cfg_attr(miri, ignore)]
-fn gc_in_func_without_program_points() -> wasmtime::Result<()> {
- for collector in [Collector::Copying, Collector::DeferredReferenceCounting] {
- let mut config = Config::default();
- config.guest_debug(true).wasm_gc(true).collector(collector);
- let engine = Engine::new(&config)?;
- let module = Module::new(
- &engine,
- r#"
- (module
- (type $a (array (mut i8)))
- (func (export "f")
- (local externref externref externref externref
- externref externref externref externref
- externref externref externref externref
- externref externref externref externref
- externref externref externref externref
- externref externref externref externref
- externref externref externref externref
- externref externref externref externref))
- (global (ref $a) (array.new_default $a (i32.const 100000)))
- (global (ref $a) (array.new_default $a (i32.const 100000)))
- (global (ref $a) (array.new_default $a (i32.const 100000))))
- "#,
- )?;
- let mut store = Store::new(&engine, ());
- Instance::new(&mut store, &module, &[])?;
- }
- Ok(())
-}
-
#[test]
#[cfg_attr(miri, ignore)]
fn gc_in_libcall_uses_correct_stack_shape() -> wasmtime::Result<()> {
diff --git a/tests/all/exceptions.rs b/tests/all/exceptions.rs
index 6d500271a7..f30e342efe 100644
--- a/tests/all/exceptions.rs
+++ b/tests/all/exceptions.rs
@@ -244,32 +244,6 @@ fn caught_externref_payload_survives_gc(config: &mut Config) -> Result<()> {
Ok(())
}
-#[wasmtime_test(collectors(Null), wasm_features(exceptions))]
-#[cfg_attr(miri, ignore)]
-fn throw_with_null_collector(config: &mut Config) -> Result<()> {
- let engine = Engine::new(config)?;
- let mut store = Store::new(&engine, ());
-
- let module = Module::new(
- &engine,
- r#"
- (module
- (tag $e (param i32))
- (func (export "throw")
- (throw $e (i32.const 42))))
- "#,
- )?;
- let instance = Instance::new(&mut store, &module, &[])?;
- let func = instance.get_func(&mut store, "throw").unwrap();
- let result = func.call(&mut store, &[], &mut []);
- assert!(result.unwrap_err().is::<ThrownException>());
-
- let exn = store.take_pending_exception().unwrap();
- assert_eq!(exn.field(&mut store, 0)?.unwrap_i32(), 42);
-
- Ok(())
-}
-
#[wasmtime_test(wasm_features(exceptions))]
#[cfg_attr(miri, ignore)]
fn exception_from_host(config: &mut Config) -> Result<()> {
diff --git a/tests/all/func.rs b/tests/all/func.rs
index 3a6219ccc4..5aceb9b2a4 100644
--- a/tests/all/func.rs
+++ b/tests/all/func.rs
@@ -2394,141 +2394,3 @@ fn wasm_to_host_trampolines_and_subtyping(config: &mut Config) -> Result<()> {
Ok(())
}
-
-/// Run a component exporting a `g: func() -> u32` function both with and
-/// without inlining; check that it returns the expected value.
-fn assert_returns_regardless_of_inlining(
- wat: &str,
- expected: u32,
- configure: impl Fn(&mut Config),
-) -> Result<()> {
- for inlining in [wasmtime::Inlining::No, wasmtime::Inlining::Yes] {
- let mut config = Config::new();
- config.compiler_inlining(inlining);
-
- // Make it so that function calls which *can* be inlined, *will* be
- // inlined.
- unsafe {
- config.cranelift_flag_set(
- "wasmtime_inlining_sum_size_threshold",
- &u32::MAX.to_string(),
- );
- }
-
- configure(&mut config);
-
- let engine = Engine::new(&config)?;
- let component = wasmtime::component::Component::new(&engine, wat)?;
- let mut store = Store::new(&engine, ());
- let instance =
- wasmtime::component::Linker::new(&engine).instantiate(&mut store, &component)?;
- let g = instance.get_typed_func::<(), (u32,)>(&mut store, "g")?;
- let (result,) = g.call(&mut store, ())?;
-
- assert_eq!(result, expected, "wrong result with {inlining:?}");
- }
- Ok(())
-}
-
-#[test]
-#[cfg_attr(miri, ignore)]
-fn issue_13538_memories() -> Result<()> {
- // `g` reads memory, has `writeit` store a new value into it, then reads the
- // same location again and returns it: the second read must observe the
- // store (`123`), not the stale value from the first read (`0`).
- assert_returns_regardless_of_inlining(
- r#"
- (component
- (core module $M
- (memory (export "mem") 1)
- (func (export "writeit") (param i32 i32)
- (i32.store (local.get 0) (local.get 1)))
- )
- (core instance $m (instantiate $M))
- (core module $N
- (import "" "mem" (memory 1))
- (import "" "writeit" (func $writeit (param i32 i32)))
- (func (export "g") (result i32)
- (i32.load (i32.const 0))
- drop
- (call $writeit (i32.const 0) (i32.const 123))
- (i32.load (i32.const 0)))
- )
- (core instance $n (instantiate $N
- (with "" (instance
- (export "mem" (memory $m "mem"))
- (export "writeit" (func $m "writeit"))))))
- (func (export "g") (result u32) (canon lift (core func $n "g"))))
- "#,
- 123,
- |_| {},
- )
-}
-
-#[test]
-#[cfg_attr(miri, ignore)]
-fn issue_13538_globals() -> Result<()> {
- // Same as `issue_13538_memories` but for globals.
- assert_returns_regardless_of_inlining(
- r#"
- (component
- (core module $M
- (global (export "glob") (mut i32) (i32.const 0))
- (func (export "writeit") (param i32)
- (global.set 0 (local.get 0)))
- )
- (core instance $m (instantiate $M))
- (core module $N
- (import "" "glob" (global $glob (mut i32)))
- (import "" "writeit" (func $writeit (param i32)))
- (func (export "g") (result i32)
- (global.get $glob)
- drop
- (call $writeit (i32.const 123))
- (global.get $glob))
- )
- (core instance $n (instantiate $N
- (with "" (instance
- (export "glob" (global $m "glob"))
- (export "writeit" (func $m "writeit"))))))
- (func (export "g") (result u32) (canon lift (core func $n "g"))))
- "#,
- 123,
- |_| {},
- )
-}
-
-#[test]
-#[cfg_attr(miri, ignore)]
-fn issue_13538_tables() -> Result<()> {
- // Same as `issue_13538_memories` but for tables.
- assert_returns_regardless_of_inlining(
- r#"
- (component
- (core module $M
- (table (export "tab") 1 1 (ref i31) (ref.i31 (i32.const 0)))
- (func (export "writeit") (param i32)
- (table.set (i32.const 0) (ref.i31 (local.get 0))))
- )
- (core instance $m (instantiate $M))
- (core module $N
- (import "" "tab" (table 1 1 (ref i31)))
- (import "" "writeit" (func $writeit (param i32)))
- (func (export "g") (result i32)
- (drop (table.get (i32.const 0)))
- (call $writeit (i32.const 123))
- (i31.get_u (table.get (i32.const 0))))
- )
- (core instance $n (instantiate $N
- (with "" (instance
- (export "tab" (table $m "tab"))
- (export "writeit" (func $m "writeit"))))))
- (func (export "g") (result u32) (canon lift (core func $n "g"))))
- "#,
- 123,
- |config| {
- config.wasm_function_references(true);
- config.wasm_gc(true);
- },
- )
-}
diff --git a/tests/all/gc.rs b/tests/all/gc.rs
index 2d045f5094..192e7b231e 100644
--- a/tests/all/gc.rs
+++ b/tests/all/gc.rs
@@ -963,55 +963,6 @@ fn table_grow_doesnt_leak() -> Result<()> {
Ok(())
}
-// This is a test that the argument to `table.init` is properly handled w.r.t.
-// write barriers and such. This doesn't use `SetFlagOnDrop` because that would
-// require initializing a table with an element initialized from a global and
-// the global keeps the externref alive regardless. Instead this has a small GC
-// heap and we continuously make more garbage than is in the heap and expect
-// this to work as when it triggers a GC everything prior should get cleaned up.
-#[test]
-#[cfg_attr(miri, ignore)]
-fn table_init_doesnt_leak() -> Result<()> {
- const SIZE: u64 = 64 << 10;
-
- let _ = env_logger::try_init();
-
- let mut config = Config::new();
- config.wasm_gc(true);
- config.wasm_function_references(true);
- config.memory_may_move(false);
- config.memory_reservation(SIZE);
- config.memory_reservation_for_growth(0);
- let engine = Engine::new(&config)?;
- let mut store = Store::new(&engine, ());
-
- let module = Module::new(
- store.engine(),
- r#"
- (module
- (table 1 arrayref)
-
- (type $a (array i31ref))
-
- (func (export "run")
- i32.const 0
- i32.const 0
- i32.const 1
- table.init $e)
- (elem $e arrayref (array.new $a (ref.i31 (i32.const 0)) (i32.const 200)))
- )
- "#,
- )?;
-
- let instance = Instance::new(&mut store, &module, &[])?;
- let func = instance.get_typed_func::<(), ()>(&mut store, "run")?;
- for _ in 0..200 {
- func.call(&mut store, ())?;
- }
-
- Ok(())
-}
-
#[test]
fn ref_matches() -> Result<()> {
let mut store = Store::<()>::default();
@@ -1138,56 +1089,6 @@ fn ref_matches() -> Result<()> {
Ok(())
}
-#[test]
-#[cfg_attr(miri, ignore)]
-fn issue_9669() -> Result<()> {
- let _ = env_logger::try_init();
-
- let mut config = Config::new();
- config.wasm_function_references(true);
- config.wasm_gc(true);
- config.collector(Collector::DeferredReferenceCounting);
-
- let engine = Engine::new(&config)?;
-
- let module = Module::new(
- &engine,
- r#"
- (module
- (type $empty (struct))
- (type $thing (struct
- (field $field1 (ref $empty))
- (field $field2 (ref $empty))
- ))
-
- (func (export "run")
- (local $object (ref $thing))
-
- struct.new $empty
- struct.new $empty
- struct.new $thing
-
- local.tee $object
- struct.get $thing $field1
- drop
-
- local.get $object
- struct.get $thing $field2
- drop
- )
- )
- "#,
- )?;
-
- let mut store = Store::new(&engine, ());
- let instance = Instance::new(&mut store, &module, &[])?;
-
- let func = instance.get_typed_func::<(), ()>(&mut store, "run")?;
- func.call(&mut store, ())?;
-
- Ok(())
-}
-
#[test]
#[cfg_attr(miri, ignore)]
fn drc_transitive_drop_cons_list() -> Result<()> {
@@ -1365,135 +1266,6 @@ fn drc_traces_the_correct_number_of_gc_refs_in_arrays() -> Result<()> {
Ok(())
}
-// Regression test for a stack-map bug in `translate_per_element_copy` (used by
-// `array.copy` on arrays whose elements are GC references).
-//
-// The per-element loop derived raw `src_elem_addr` / `dst_elem_addr` pointers
-// once and used only those raw pointers inside the loop body. The source and
-// destination array gc-refs themselves were dead in CLIF inside the loop, so
-// they were absent from the stack maps at safe points there. Once the DRC
-// collector started firing `force_gc` from inside the read barrier (when the
-// over-approximated-stack-roots list grew past 1024 entries), a GC could run
-// mid-copy with neither array marked from any frame's stack map. Sweep could
-// then drop the arrays from OASR, freeing them and cascading dec-refs through
-// their elements, after which the rest of the copy read from freed memory.
-//
-// The fix passes the source and destination array gc-refs as block params
-// through the forward and backward iteration blocks so they stay live across
-// the per-element loop.
-#[test]
-#[cfg_attr(miri, ignore)]
-fn drc_array_copy_keeps_arrays_alive_across_in_loop_gc() -> Result<()> {
- let _ = env_logger::try_init();
-
- let mut config = Config::new();
- config.wasm_function_references(true);
- config.wasm_gc(true);
- config.collector(Collector::DeferredReferenceCounting);
- // Keep the GC heap small so allocations cycle back through the free
- // list quickly. This dramatically increases the chance that any slot
- // freed mid-copy will be reused before the test's verify pass reads
- // from it, making the bug observable.
- config.gc_heap_reservation(128 * 1024);
- config.gc_heap_reservation_for_growth(0);
-
- let engine = Engine::new(&config)?;
- let mut store = Store::new(&engine, ());
-
- let module = Module::new(
- &engine,
- r#"
- (module
- (import "wasmtime" "gc" (func $gc))
- (type $box (struct (field i32)))
- (type $arr (array (mut (ref null $box))))
-
- ;; Put the `array.copy` in a helper function so the source
- ;; and destination gc-refs are visibly dead in CLIF inside
- ;; the per-element loop -- they are function parameters
- ;; that are only used at the top of the function to compute
- ;; the initial address.
- (func $do_copy
- (param $src (ref null $arr))
- (param $dst (ref null $arr))
- (param $len i32)
- (array.copy $arr $arr
- (local.get $dst) (i32.const 0)
- (local.get $src) (i32.const 0)
- (local.get $len)))
-
- (func (export "test") (result i32)
- (local $src (ref null $arr))
- (local $dst (ref null $arr))
- (local $i i32)
- (local $sum i32)
-
- ;; N=2048 > 1024 so the per-element read barrier
- ;; definitely fires `force_gc` during the copy.
- (local.set $src (array.new $arr (ref.null $box) (i32.const 2048)))
- (local.set $i (i32.const 0))
- (loop $fill
- (array.set $arr (local.get $src) (local.get $i)
- (struct.new $box (local.get $i)))
- (local.set $i (i32.add (local.get $i) (i32.const 1)))
- (br_if $fill (i32.lt_s (local.get $i) (i32.const 2048))))
-
- (local.set $dst (array.new $arr (ref.null $box) (i32.const 2048)))
-
- (call $gc)
-
- (call $do_copy (local.get $src) (local.get $dst) (i32.const 2048))
-
- ;; Drop the source local and force a GC so any
- ;; cascade-freed elements that should still be alive
- ;; via $dst would surface as either a trap (cast
- ;; failure / out-of-bounds) or wrong $dst contents.
- (local.set $src (ref.null $arr))
- (call $gc)
-
- ;; Heavily allocate to reuse any freed slots. Each
- ;; iteration allocates a $box with sentinel value -1;
- ;; if any element of $dst was a stale reference to a
- ;; cascade-freed $box, its slot gets reused here and
- ;; reading it back will see -1 rather than its
- ;; original index.
- (local.set $i (i32.const 0))
- (loop $churn
- (drop (struct.new $box (i32.const -1)))
- (local.set $i (i32.add (local.get $i) (i32.const 1)))
- (br_if $churn (i32.lt_s (local.get $i) (i32.const 4096))))
-
- (call $gc)
-
- (local.set $i (i32.const 0))
- (local.set $sum (i32.const 0))
- (loop $verify
- (local.set $sum
- (i32.add (local.get $sum)
- (struct.get $box 0
- (array.get $arr (local.get $dst) (local.get $i)))))
- (local.set $i (i32.add (local.get $i) (i32.const 1)))
- (br_if $verify (i32.lt_s (local.get $i) (i32.const 2048))))
-
- (local.get $sum)))
- "#,
- )?;
-
- let mut linker = Linker::new(&engine);
- linker.func_wrap("wasmtime", "gc", |mut caller: Caller<_>| -> Result<()> {
- caller.gc(None)?;
- Ok(())
- })?;
- let instance = linker.instantiate(&mut store, &module)?;
- let test = instance.get_typed_func::<(), i32>(&mut store, "test")?;
- let result = test.call(&mut store, ())?;
-
- // Sum of 0..2048 = 2048 * 2047 / 2.
- assert_eq!(result, 2_096_128);
-
- Ok(())
-}
-
// Test that we can completely fill the GC heap until we get an OOM. This
// exercises growing the GC heap and that we configure compilation tunables and
// runtime memories backing GC heaps correctly.
@@ -1737,77 +1509,6 @@ fn owned_rooted_lots_of_root_creation() -> Result<()> {
Ok(())
}
-#[test]
-#[cfg_attr(miri, ignore)]
-fn instantiate_global_init_oom() -> Result<()> {
- let mut config = Config::new();
- config.wasm_gc(true);
- config.wasm_function_references(true);
- config.memory_may_move(false);
- config.memory_reservation(64 << 10);
- config.memory_reservation_for_growth(0);
- config.gc_heap_may_move(false);
- config.gc_heap_reservation(64 << 10);
- config.gc_heap_reservation_for_growth(0);
- let engine = Engine::new(&config)?;
- let mut store = Store::new(&engine, ());
-
- let module = Module::new(
- store.engine(),
- r#"
- (module
- (table 100 arrayref)
- (type $a (array i31ref))
- (global (ref $a) (array.new_default $a (i32.const 10000000)))
- )
- "#,
- )?;
-
- Instance::new(&mut store, &module, &[])
- .unwrap_err()
- .downcast::<GcHeapOutOfMemory<()>>()?;
-
- Ok(())
-}
-
-#[test]
-#[cfg_attr(miri, ignore)]
-fn elem_const_eval_oom() -> Result<()> {
- let mut config = Config::new();
- config.wasm_gc(true);
- config.wasm_function_references(true);
- config.memory_may_move(false);
- config.memory_reservation(64 << 10);
- config.memory_reservation_for_growth(0);
- config.gc_heap_may_move(false);
- config.gc_heap_reservation(64 << 10);
- config.gc_heap_reservation_for_growth(0);
- let engine = Engine::new(&config)?;
- let mut store = Store::new(&engine, ());
-
- let module = Module::new(
- store.engine(),
- r#"
- (module
- (type $a (array i31ref))
- (elem arrayref
- (array.new_default $a (i32.const 100))
- (array.new_default $a (i32.const 10000))
- (array.new_default $a (i32.const 10000))
- (array.new_default $a (i32.const 10000))
- (array.new_default $a (i32.const 1000000))
- )
- )
- "#,
- )?;
-
- Instance::new(&mut store, &module, &[])
- .unwrap_err()
- .downcast::<GcHeapOutOfMemory<()>>()?;
-
- Ok(())
-}
-
#[test]
#[cfg_attr(miri, ignore)]
fn dropped_passive_elems_do_not_leak() -> Result<()> {
@@ -1942,38 +1643,6 @@ fn pooling_gc_different_configs_rejected() -> Result<()> {
Ok(())
}
-#[test]
-#[cfg_attr(miri, ignore)]
-fn issue_13141_gc_heap_may_not_move() -> Result<()> {
- let mut config = Config::new();
- config.wasm_gc(true);
- config.gc_heap_may_move(false);
-
- let engine = Engine::new(&config)?;
-
- let module = Module::new(
- &engine,
- r#"
- (module
- (type $a (array (mut i8)))
-
- (global $g (mut (ref $a)) (array.new_default $a (i32.const 12)))
-
- (func (export "array_get_nth") (param $p i32) (result i32)
- (array.get_u $a (global.get $g) (local.get $p))
- )
- )
- "#,
- )?;
-
- let mut store = Store::new(&engine, ());
- let instance = Instance::new(&mut store, &module, &[])?;
- let array_get_nth = instance.get_typed_func::<i32, i32>(&mut store, "array_get_nth")?;
- let result = array_get_nth.call(&mut store, 0)?;
- assert_eq!(result, 0);
- Ok(())
-}
-
#[test]
#[cfg_attr(miri, ignore)]
fn memory_guard_pages_but_no_gc_heap_guard_pages() -> Result<()> {
diff --git a/tests/all/memory.rs b/tests/all/memory.rs
index 54a1348a43..4f83073b8b 100644
--- a/tests/all/memory.rs
+++ b/tests/all/memory.rs
@@ -400,43 +400,6 @@ fn massive_64_bit_still_limited() -> Result<()> {
}
}
-#[wasmtime_test]
-#[cfg_attr(miri, ignore)]
-fn tiny_static_heap(config: &mut Config) -> Result<()> {
- // The size of the memory in the module below is the exact same size as
- // the static memory size limit in the configuration. This is intended to
- // specifically test that a load of all the valid addresses of the memory
- // all pass bounds-checks in cranelift to help weed out any off-by-one bugs.
- config.memory_reservation(1 << 16);
- let engine = Engine::new(&config)?;
- let mut store = Store::new(&engine, ());
-
- let module = Module::new(
- &engine,
- r#"
- (module
- (memory 1 1)
- (func (export "run")
- (local $i i32)
-
- (loop
- (if (i32.eq (local.get $i) (i32.const 65536))
- (then (return)))
- (drop (i32.load8_u (local.get $i)))
- (local.set $i (i32.add (local.get $i) (i32.const 1)))
- br 0
- )
- )
- )
- "#,
- )?;
-
- let i = Instance::new(&mut store, &module, &[])?;
- let f = i.get_typed_func::<(), ()>(&mut store, "run")?;
- f.call(&mut store, ())?;
- Ok(())
-}
-
#[test]
fn static_forced_max() -> Result<()> {
let mut config = Config::new();
@@ -775,112 +738,6 @@ fn non_page_aligned_static_memory() -> Result<()> {
Ok(())
}
-// When a memory's minimum size exceeds `memory_reservation`, the runtime sizes
-// the allocation from the minimum, so compilers must not treat the reservation
-// as an upper bound on accessible memory.
-#[wasmtime_test]
-#[cfg_attr(miri, ignore)]
-fn minimum_larger_than_reservation_without_moving(cfg: &mut Config) -> Result<()> {
- cfg.memory_reservation(0);
- cfg.memory_may_move(false);
- let engine = Engine::new(cfg)?;
- let module = Module::new(
- &engine,
- r#"
- (module
- (memory 2)
- (func (export "store") (param i32 i32)
- local.get 0
- local.get 1
- i32.store)
- (func (export "load") (param i32) (result i32)
- local.get 0
- i32.load)
- (func (export "load_offset") (param i32) (result i32)
- local.get 0
- i32.load offset=70000)
- )
- "#,
- )?;
- let mut store = Store::new(&engine, ());
- let instance = Instance::new(&mut store, &module, &[])?;
- let store_fn = instance.get_typed_func::<(u32, u32), ()>(&mut store, "store")?;
- let load = instance.get_typed_func::<u32, u32>(&mut store, "load")?;
- let load_offset = instance.get_typed_func::<u32, u32>(&mut store, "load_offset")?;
-
- store_fn.call(&mut store, (0, 42))?;
- assert_eq!(load.call(&mut store, 0)?, 42);
- store_fn.call(&mut store, (70_000, 7))?;
- assert_eq!(load_offset.call(&mut store, 0)?, 7);
- assert_eq!(load.call(&mut store, 2 * 65536 - 4)?, 0);
-
- // Accesses past the minimum size must still trap.
- let trap = load
- .call(&mut store, 2 * 65536 - 3)
- .unwrap_err()
- .downcast::<Trap>()?;
- assert_eq!(trap, Trap::MemoryOutOfBounds);
- let trap = load_offset
- .call(&mut store, 2 * 65536 - 70_000 - 3)
- .unwrap_err()
- .downcast::<Trap>()?;
- assert_eq!(trap, Trap::MemoryOutOfBounds);
- Ok(())
-}
-
-#[wasmtime_test]
-#[cfg_attr(miri, ignore)]
-fn imported_memory_larger_than_reservation_without_moving(cfg: &mut Config) -> Result<()> {
- cfg.wasm_memory64(true);
- cfg.wasm_multi_memory(true);
- cfg.memory_reservation(65536);
- cfg.memory_may_move(false);
- let engine = Engine::new(cfg)?;
- let module = Module::new(
- &engine,
- r#"
- (module
- (import "" "m32" (memory 1))
- (import "" "m64" (memory i64 1))
- (func (export "load32") (param i32) (result i32)
- local.get 0
- i32.load8_u 0)
- (func (export "load64") (param i64) (result i32)
- local.get 0
- i32.load8_u 1 offset=1)
- )
- "#,
- )?;
- let mut store = Store::new(&engine, ());
- let m32 = Memory::new(&mut store, MemoryType::new(4, None)?)?;
- let m64 = Memory::new(&mut store, MemoryType::new64(4, None)?)?;
- m32.data_mut(&mut store)[4 * 65536 - 1] = 1;
- m64.data_mut(&mut store)[4 * 65536 - 1] = 2;
- let instance = Instance::new(&mut store, &module, &[m32.into(), m64.into()])?;
- let load32 = instance.get_typed_func::<u32, u32>(&mut store, "load32")?;
- let load64 = instance.get_typed_func::<u64, u32>(&mut store, "load64")?;
-
- // Accesses beyond the importer's minimum size and the memory reservation,
- // but within the actual memory's size, must succeed.
- assert_eq!(load32.call(&mut store, 0x20000)?, 0);
- assert_eq!(load32.call(&mut store, 4 * 65536 - 1)?, 1);
- assert_eq!(load64.call(&mut store, 0x20000)?, 0);
- assert_eq!(load64.call(&mut store, 4 * 65536 - 2)?, 2);
-
- // Accesses past the actual memory's size must still trap.
- let trap = load32
- .call(&mut store, 4 * 65536)
- .unwrap_err()
- .downcast::<Trap>()?;
- assert_eq!(trap, Trap::MemoryOutOfBounds);
- let trap = load64
- .call(&mut store, 4 * 65536 - 1)
- .unwrap_err()
- .downcast::<Trap>()?;
- assert_eq!(trap, Trap::MemoryOutOfBounds);
- Ok(())
-}
-
#[test]
fn new_memory_with_custom_page_size() -> Result<()> {
let engine = Engine::default();
diff --git a/tests/all/stack_switching.rs b/tests/all/stack_switching.rs
index 56c86d3040..c0f3c5a4a0 100644
--- a/tests/all/stack_switching.rs
+++ b/tests/all/stack_switching.rs
@@ -250,71 +250,6 @@ mod wasi {
}
}
-/// Regression test for https://github.com/bytecodealliance/wasmtime/issues/13750.
-///
-/// A GC reference returned through a continuation payload must retain
-/// its stack-map metadata while it is live on the operand stack
-/// across subsequent GC safepoints.
-#[cfg_attr(miri, ignore)]
-#[test]
-fn continuation_result_gc_ref_on_operand_stack() -> Result<()> {
- let mut config = Config::new();
- config
- .wasm_stack_switching(true)
- .wasm_exceptions(true)
- .wasm_function_references(true)
- .wasm_gc(true)
- .collector(Collector::Copying);
-
- #[cfg(gc_zeal)]
- {
- let _ = config.gc_zeal_alloc_counter(std::num::NonZeroU32::new(1));
- }
-
- let engine = Engine::new(&config)?;
- let module = Module::new(
- &engine,
- r#"
- (module
- (type $S (struct (field $x i32)))
- (type $A (array i64))
- (type $ft (func (result (ref $S))))
- (type $ct (cont $ft))
-
- (func $target (result (ref $S))
- (struct.new $S (i32.const 0x12345678)))
- (elem declare func $target)
-
- (func (export "run") (result i32)
- (local $k (ref null $ct))
- (local $i i32)
- (local.set $k (cont.new $ct (ref.func $target)))
-
- ;; Keep the continuation's GC-reference result on the operand
- ;; stack, rather than storing it in a GC-typed local.
- (resume $ct (local.get $k))
-
- ;; Force collections while that operand-stack value is the
- ;; only live reference to the struct.
- (local.set $i (i32.const 0))
- (loop $again
- (drop (array.new_default $A (i32.const 256)))
- (local.set $i (i32.add (local.get $i) (i32.const 1)))
- (br_if $again
- (i32.lt_u (local.get $i) (i32.const 2000))))
-
- (struct.get $S $x))
- )
- "#,
- )?;
-
- let mut store = Store::new(&engine, ());
- let instance = Instance::new(&mut store, &module, &[])?;
- let run = instance.get_typed_func::<(), i32>(&mut store, "run")?;
- assert_eq!(run.call(&mut store, ())?, 0x12345678);
- Ok(())
-}
-
/// Tests interaction with host functions. Note that the interaction with host
/// functions and traps is covered by the module `traps` further down.
mod host {
diff --git a/tests/misc_testsuite/component-model/handle-table-limit-raised.wast b/tests/misc_testsuite/component-model/handle-table-limit-raised.wast
new file mode 100644
index 0000000000..0843062ec0
--- /dev/null
+++ b/tests/misc_testsuite/component-model/handle-table-limit-raised.wast
@@ -0,0 +1,34 @@
+;;! flags = "-S max-component-handles=1000"
+
+;; A configured handle limit above the one in `handle-table-limit.wast` admits
+;; a spray that one rejects, and is itself enforced: it's below the default
+;; limit, so a spray past it still traps.
+(component definition $Tester
+ (type $r (resource (rep i32)))
+ (core func $resource.new (canon resource.new $r))
+
+ (core module $m
+ (import "" "resource.new" (func $resource.new (param i32) (result i32)))
+ (func (export "spray") (param $n i32) (result i32)
+ (local $i i32)
+ (loop $l
+ (if (i32.lt_u (local.get $i) (local.get $n))
+ (then
+ (drop (call $resource.new (local.get $i)))
+ (local.set $i (i32.add (local.get $i) (i32.const 1)))
+ (br $l))))
+ (local.get $i)))
+ (core instance $i (instantiate $m
+ (with "" (instance
+ (export "resource.new" (func $resource.new))
+ ))
+ ))
+
+ (func (export "spray") (param "n" u32) (result u32)
+ (canon lift (core func $i "spray"))))
+
+(component instance $t $Tester)
+(assert_return (invoke "spray" (u32.const 50)) (u32.const 50))
+
+(component instance $t $Tester)
+(assert_trap (invoke "spray" (u32.const 1001)) "store handle limit exceeded")
diff --git a/tests/misc_testsuite/component-model/handle-table-limit.wast b/tests/misc_testsuite/component-model/handle-table-limit.wast
new file mode 100644
index 0000000000..1747244fcb
--- /dev/null
+++ b/tests/misc_testsuite/component-model/handle-table-limit.wast
@@ -0,0 +1,179 @@
+;;! multi_memory = true
+;;! flags = "-S max-component-handles=20"
+
+;; Tests for the store-level cap on simultaneously-live component-model
+;; handles, set to 20 here. Each component instantiation gets a fresh store.
+;;
+;; `$C` is instantiated twice, so each instance has its own handle table.
+;; `spray(n)` allocates `n` live handles; `churn(n)` allocates and drops one
+;; `n` times, staying at one live; `drop-all(n)` drops handles `1..=n`, the
+;; ones a first `spray(n)` returns.
+(component definition $Tester
+ (component $C
+ (type $r (resource (rep i32)))
+ (core func $resource.new (canon resource.new $r))
+ (core func $resource.drop (canon resource.drop $r))
+
+ (core module $m
+ (import "" "resource.new" (func $resource.new (param i32) (result i32)))
+ (import "" "resource.drop" (func $resource.drop (param i32)))
+ (func (export "spray") (param $n i32) (result i32)
+ (local $i i32)
+ (loop $l
+ (if (i32.lt_u (local.get $i) (local.get $n))
+ (then
+ (drop (call $resource.new (local.get $i)))
+ (local.set $i (i32.add (local.get $i) (i32.const 1)))
+ (br $l))))
+ (local.get $i))
+ (func (export "churn") (param $n i32) (result i32)
+ (local $i i32)
+ (loop $l
+ (if (i32.lt_u (local.get $i) (local.get $n))
+ (then
+ (call $resource.drop (call $resource.new (local.get $i)))
+ (local.set $i (i32.add (local.get $i) (i32.const 1)))
+ (br $l))))
+ (local.get $i))
+ (func (export "drop-all") (param $n i32)
+ (local $i i32)
+ (loop $l
+ (if (i32.lt_u (local.get $i) (local.get $n))
+ (then
+ (local.set $i (i32.add (local.get $i) (i32.const 1)))
+ (call $resource.drop (local.get $i))
+ (br $l))))))
+ (core instance $i (instantiate $m
+ (with "" (instance
+ (export "resource.new" (func $resource.new))
+ (export "resource.drop" (func $resource.drop))
+ ))
+ ))
+
+ (func (export "spray") (param "n" u32) (result u32)
+ (canon lift (core func $i "spray")))
+ (func (export "churn") (param "n" u32) (result u32)
+ (canon lift (core func $i "churn")))
+ (func (export "drop-all") (param "n" u32)
+ (canon lift (core func $i "drop-all"))))
+
+ (instance $i0 (instantiate $C))
+ (export "spray0" (func $i0 "spray"))
+ (export "churn0" (func $i0 "churn"))
+ (export "drop-all0" (func $i0 "drop-all"))
+ (instance $i1 (instantiate $C))
+ (export "spray1" (func $i1 "spray")))
+
+;; The cap is per store, not per table: 12 handles in each of two instances
+;; cross the limit together but not individually.
+(component instance $t $Tester)
+(assert_return (invoke "spray0" (u32.const 12)) (u32.const 12))
+(assert_trap (invoke "spray1" (u32.const 12)) "store handle limit exceeded")
+
+;; The cap counts live table slots, not cumulative allocations: churning far
+;; past the limit succeeds because each dropped slot is reused, and the whole
+;; budget is available afterwards.
+(component instance $t $Tester)
+(assert_return (invoke "churn0" (u32.const 2000)) (u32.const 2000))
+(assert_return (invoke "spray0" (u32.const 15)) (u32.const 15))
+
+;; Freed slots still count: after the first instance's table grows to 15 slots
+;; and frees them all, the second can't grow its table past the remaining 5.
+(component instance $t $Tester)
+(assert_return (invoke "spray0" (u32.const 15)) (u32.const 15))
+(assert_return (invoke "drop-all0" (u32.const 15)))
+(assert_trap (invoke "spray1" (u32.const 10)) "store handle limit exceeded")
+
+;; Borrows lent to the resource's owner count against the limit while the call
+;; is active, and return their budget when it returns.
+;;
+;; `$D` defines a resource and `$U` passes a `list<borrow<R>>` of `n` copies of
+;; one handle to `$D`'s `take`, `k` times. `$D` receives reps, so no handles
+;; are created for the borrows, but each lend still counts against the limit
+;; until `take` returns.
+(component definition $Lender
+ (component $D
+ (type $R (resource (rep i32)))
+ (core func $resource.new (canon resource.new $R))
+
+ (core module $m
+ (import "" "resource.new" (func $resource.new (param i32) (result i32)))
+ (memory (export "mem") 1)
+ (func (export "realloc") (param i32 i32 i32 i32) (result i32)
+ (i32.const 16))
+ (func (export "make") (result i32)
+ (call $resource.new (i32.const 42)))
+ (func (export "take") (param i32 i32) (result i32)
+ (local.get 1)))
+ (core instance $i (instantiate $m
+ (with "" (instance
+ (export "resource.new" (func $resource.new))
+ ))
+ ))
+
+ (export $R' "r" (type $R))
+ (func (export "make") (result (own $R'))
+ (canon lift (core func $i "make")))
+ (func (export "take") (param "xs" (list (borrow $R'))) (result u32)
+ (canon lift (core func $i "take")
+ (memory (core memory $i "mem"))
+ (realloc (core func $i "realloc")))))
+ (instance $d (instantiate $D))
+
+ (component $U
+ (import "r" (type $R (sub resource)))
+ (import "make" (func $make (result (own $R))))
+ (import "take" (func $take (param "xs" (list (borrow $R))) (result u32)))
+
+ (core module $libc (memory (export "mem") 1))
+ (core instance $libc (instantiate $libc))
+ (core func $make (canon lower (func $make)))
+ (core func $take
+ (canon lower (func $take) (memory (core memory $libc "mem"))))
+
+ (core module $m
+ (import "" "mem" (memory 1))
+ (import "" "make" (func $make (result i32)))
+ (import "" "take" (func $take (param i32 i32) (result i32)))
+ (func (export "run") (param $n i32) (param $k i32) (result i32)
+ (local $h i32)
+ (local $i i32)
+ (local.set $h (call $make))
+ (loop $l
+ (if (i32.lt_u (local.get $i) (local.get $n))
+ (then
+ (i32.store (i32.shl (local.get $i) (i32.const 2)) (local.get $h))
+ (local.set $i (i32.add (local.get $i) (i32.const 1)))
+ (br $l))))
+ (local.set $i (i32.const 0))
+ (loop $l
+ (if (i32.lt_u (local.get $i) (local.get $k))
+ (then
+ (drop (call $take (i32.const 0) (local.get $n)))
+ (local.set $i (i32.add (local.get $i) (i32.const 1)))
+ (br $l))))
+ (local.get $k)))
+ (core instance $i (instantiate $m
+ (with "" (instance
+ (export "mem" (memory $libc "mem"))
+ (export "make" (func $make))
+ (export "take" (func $take))
+ ))
+ ))
+
+ (func (export "run") (param "n" u32) (param "k" u32) (result u32)
+ (canon lift (core func $i "run"))))
+ (instance $u (instantiate $U
+ (with "r" (type $d "r"))
+ (with "make" (func $d "make"))
+ (with "take" (func $d "take"))))
+ (export "run" (func $u "run")))
+
+;; Ten lends at a time, many times over, fit.
+(component instance $l $Lender)
+(assert_return (invoke "run" (u32.const 10) (u32.const 100)) (u32.const 100))
+
+;; Fifty lends in one call don't.
+(component instance $l $Lender)
+(assert_trap (invoke "run" (u32.const 50) (u32.const 1))
+ "store handle limit exceeded")
diff --git a/tests/misc_testsuite/component-model/issue-13538.wast b/tests/misc_testsuite/component-model/issue-13538.wast
new file mode 100644
index 0000000000..29828f6d77
--- /dev/null
+++ b/tests/misc_testsuite/component-model/issue-13538.wast
@@ -0,0 +1,80 @@
+;;! gc = true
+;;! flags = """
+;;! -C inlining=y
+;;! -C cranelift-wasmtime-inlining-sum-size-threshold=4294967295
+;;! """
+
+;; Test for #13538
+;;
+;; With inlining forced on for every call that can be inlined, `g` reads an
+;; entity imported from another instance, calls that instance's `writeit` to
+;; change it, and reads it again. The second read must observe the write
+;; (`123`), not the stale value from the first read (`0`).
+
+;; Memories.
+(component
+ (core module $M
+ (memory (export "mem") 1)
+ (func (export "writeit") (param i32 i32)
+ (i32.store (local.get 0) (local.get 1))))
+ (core instance $m (instantiate $M))
+ (core module $N
+ (import "" "mem" (memory 1))
+ (import "" "writeit" (func $writeit (param i32 i32)))
+ (func (export "g") (result i32)
+ (i32.load (i32.const 0))
+ drop
+ (call $writeit (i32.const 0) (i32.const 123))
+ (i32.load (i32.const 0))))
+ (core instance $n (instantiate $N
+ (with "" (instance
+ (export "mem" (memory $m "mem"))
+ (export "writeit" (func $m "writeit"))))))
+ (func (export "g") (result u32) (canon lift (core func $n "g"))))
+
+(assert_return (invoke "g") (u32.const 123))
+
+;; Globals.
+(component
+ (core module $M
+ (global (export "glob") (mut i32) (i32.const 0))
+ (func (export "writeit") (param i32)
+ (global.set 0 (local.get 0))))
+ (core instance $m (instantiate $M))
+ (core module $N
+ (import "" "glob" (global $glob (mut i32)))
+ (import "" "writeit" (func $writeit (param i32)))
+ (func (export "g") (result i32)
+ (global.get $glob)
+ drop
+ (call $writeit (i32.const 123))
+ (global.get $glob)))
+ (core instance $n (instantiate $N
+ (with "" (instance
+ (export "glob" (global $m "glob"))
+ (export "writeit" (func $m "writeit"))))))
+ (func (export "g") (result u32) (canon lift (core func $n "g"))))
+
+(assert_return (invoke "g") (u32.const 123))
+
+;; Tables.
+(component
+ (core module $M
+ (table (export "tab") 1 1 (ref i31) (ref.i31 (i32.const 0)))
+ (func (export "writeit") (param i32)
+ (table.set (i32.const 0) (ref.i31 (local.get 0)))))
+ (core instance $m (instantiate $M))
+ (core module $N
+ (import "" "tab" (table 1 1 (ref i31)))
+ (import "" "writeit" (func $writeit (param i32)))
+ (func (export "g") (result i32)
+ (drop (table.get (i32.const 0)))
+ (call $writeit (i32.const 123))
+ (i31.get_u (table.get (i32.const 0)))))
+ (core instance $n (instantiate $N
+ (with "" (instance
+ (export "tab" (table $m "tab"))
+ (export "writeit" (func $m "writeit"))))))
+ (func (export "g") (result u32) (canon lift (core func $n "g"))))
+
+(assert_return (invoke "g") (u32.const 123))
diff --git a/tests/misc_testsuite/exceptions-null-collector.wast b/tests/misc_testsuite/exceptions-null-collector.wast
new file mode 100644
index 0000000000..567a710617
--- /dev/null
+++ b/tests/misc_testsuite/exceptions-null-collector.wast
@@ -0,0 +1,19 @@
+;;! exceptions = true
+;;! flags = "-C collector=null"
+
+;; Exceptions work with the null collector, both when caught in wasm and when
+;; they escape to the host.
+(module
+ (tag $e (param i32))
+
+ (func $throw (export "throw")
+ (throw $e (i32.const 42)))
+
+ (func (export "catch") (result i32)
+ (block $h (result i32)
+ (try_table (catch $e $h)
+ (call $throw))
+ unreachable)))
+
+(assert_exception (invoke "throw"))
+(assert_return (invoke "catch") (i32.const 42))
diff --git a/tests/misc_testsuite/gc/const-eval-oom.wast b/tests/misc_testsuite/gc/const-eval-oom.wast
new file mode 100644
index 0000000000..9531f5730d
--- /dev/null
+++ b/tests/misc_testsuite/gc/const-eval-oom.wast
@@ -0,0 +1,33 @@
+;;! gc = true
+;;! bulk_memory = true
+;;! flags = """
+;;! -O memory-may-move=n
+;;! -O memory-reservation=65536
+;;! -O memory-reservation-for-growth=0
+;;! -O gc-heap-may-move=n
+;;! -O gc-heap-reservation=65536
+;;! -O gc-heap-reservation-for-growth=0
+;;! """
+
+;; Running out of GC heap while evaluating constant expressions during
+;; instantiation fails the instantiation instead of panicking.
+
+;; In a global initializer.
+(assert_trap
+ (module
+ (table 100 arrayref)
+ (type $a (array i31ref))
+ (global (ref $a) (array.new_default $a (i32.const 10000000))))
+ "GC heap out of memory")
+
+;; In an element segment.
+(assert_trap
+ (module
+ (type $a (array i31ref))
+ (elem arrayref
+ (array.new_default $a (i32.const 100))
+ (array.new_default $a (i32.const 10000))
+ (array.new_default $a (i32.const 10000))
+ (array.new_default $a (i32.const 10000))
+ (array.new_default $a (i32.const 1000000))))
+ "GC heap out of memory")
diff --git a/tests/misc_testsuite/gc/drc-array-copy-in-loop-gc.wast b/tests/misc_testsuite/gc/drc-array-copy-in-loop-gc.wast
new file mode 100644
index 0000000000..d8b0f8213c
--- /dev/null
+++ b/tests/misc_testsuite/gc/drc-array-copy-in-loop-gc.wast
@@ -0,0 +1,90 @@
+;;! gc = true
+;;! flags = """
+;;! -C collector=drc
+;;! -O gc-heap-reservation=131072
+;;! -O gc-heap-reservation-for-growth=0
+;;! """
+
+;; Regression test for a stack-map bug in `translate_per_element_copy`, which
+;; implements `array.copy` on arrays of GC references.
+;;
+;; The per-element loop computed raw element addresses once and used only
+;; those inside the loop, so the source and destination arrays were dead in
+;; CLIF there and missing from stack maps at its safe points. Once the DRC
+;; collector's read barrier started calling `force_gc` (when the
+;; over-approximated-stack-roots list grows past 1024 entries), a GC could run
+;; mid-copy with neither array rooted, free them, and cascade dec-refs through
+;; their elements, after which the copy read freed memory.
+;;
+;; The small GC heap makes freed slots get reused quickly, so a stale element
+;; is observable.
+(module
+ (import "wasmtime" "gc" (func $gc))
+ (type $box (struct (field i32)))
+ (type $arr (array (mut (ref null $box))))
+
+ ;; The `array.copy` is in a helper so the source and destination arrays are
+ ;; parameters used only to compute the initial addresses, and so are dead
+ ;; inside the per-element loop.
+ (func $do_copy
+ (param $src (ref null $arr))
+ (param $dst (ref null $arr))
+ (param $len i32)
+ (array.copy $arr $arr
+ (local.get $dst) (i32.const 0)
+ (local.get $src) (i32.const 0)
+ (local.get $len)))
+
+ (func (export "test") (result i32)
+ (local $src (ref null $arr))
+ (local $dst (ref null $arr))
+ (local $i i32)
+ (local $sum i32)
+
+ ;; 2048 > 1024, so the per-element read barrier fires `force_gc` during
+ ;; the copy.
+ (local.set $src
+ (array.new $arr (ref.null $box) (i32.const 2048)))
+ (local.set $i (i32.const 0))
+ (loop $fill
+ (array.set $arr (local.get $src) (local.get $i)
+ (struct.new $box (local.get $i)))
+ (local.set $i (i32.add (local.get $i) (i32.const 1)))
+ (br_if $fill (i32.lt_s (local.get $i) (i32.const 2048))))
+
+ (local.set $dst
+ (array.new $arr (ref.null $box) (i32.const 2048)))
+
+ (call $gc)
+
+ (call $do_copy (local.get $src) (local.get $dst) (i32.const 2048))
+
+ ;; Drop the source and collect, so elements wrongly freed while still
+ ;; reachable from $dst show up as a trap or wrong contents below.
+ (local.set $src (ref.null $arr))
+ (call $gc)
+
+ ;; Allocate heavily to reuse freed slots. A stale element of $dst would
+ ;; then read back as -1 rather than its index.
+ (local.set $i (i32.const 0))
+ (loop $churn
+ (drop (struct.new $box (i32.const -1)))
+ (local.set $i (i32.add (local.get $i) (i32.const 1)))
+ (br_if $churn (i32.lt_s (local.get $i) (i32.const 4096))))
+
+ (call $gc)
+
+ (local.set $i (i32.const 0))
+ (local.set $sum (i32.const 0))
+ (loop $verify
+ (local.set $sum
+ (i32.add (local.get $sum)
+ (struct.get $box 0
+ (array.get $arr (local.get $dst) (local.get $i)))))
+ (local.set $i (i32.add (local.get $i) (i32.const 1)))
+ (br_if $verify (i32.lt_s (local.get $i) (i32.const 2048))))
+
+ (local.get $sum)))
+
+;; The sum of 0..2048 is 2048 * 2047 / 2.
+(assert_return (invoke "test") (i32.const 2096128))
diff --git a/tests/misc_testsuite/gc/guest-debug-no-program-points.wast b/tests/misc_testsuite/gc/guest-debug-no-program-points.wast
new file mode 100644
index 0000000000..f283bfa895
--- /dev/null
+++ b/tests/misc_testsuite/gc/guest-debug-no-program-points.wast
@@ -0,0 +1,21 @@
+;;! gc = true
+;;! flags = "-D guest-debug"
+
+;; Regression test for #14563. With guest debugging, some generated functions,
+;; e.g. the one running the module's global initializers, have no program
+;; points for a wasm PC. The large global initializers force GCs during
+;; instantiation, and nothing should go awry as a result.
+(module
+ (type $a (array (mut i8)))
+ (func (export "f")
+ (local externref externref externref externref
+ externref externref externref externref
+ externref externref externref externref
+ externref externref externref externref
+ externref externref externref externref
+ externref externref externref externref
+ externref externref externref externref
+ externref externref externref externref))
+ (global (ref $a) (array.new_default $a (i32.const 100000)))
+ (global (ref $a) (array.new_default $a (i32.const 100000)))
+ (global (ref $a) (array.new_default $a (i32.const 100000))))
diff --git a/tests/misc_testsuite/gc/issue-13141.wast b/tests/misc_testsuite/gc/issue-13141.wast
new file mode 100644
index 0000000000..ad15c598b1
--- /dev/null
+++ b/tests/misc_testsuite/gc/issue-13141.wast
@@ -0,0 +1,12 @@
+;;! gc = true
+;;! flags = "-O gc-heap-may-move=n"
+
+(module
+ (type $a (array (mut i8)))
+
+ (global $g (mut (ref $a)) (array.new_default $a (i32.const 12)))
+
+ (func (export "array-get-nth") (param $p i32) (result i32)
+ (array.get_u $a (global.get $g) (local.get $p))))
+
+(assert_return (invoke "array-get-nth" (i32.const 0)) (i32.const 0))
diff --git a/tests/misc_testsuite/gc/issue-9669.wast b/tests/misc_testsuite/gc/issue-9669.wast
new file mode 100644
index 0000000000..54b5478cfe
--- /dev/null
+++ b/tests/misc_testsuite/gc/issue-9669.wast
@@ -0,0 +1,24 @@
+;;! gc = true
+
+(module
+ (type $empty (struct))
+ (type $thing (struct
+ (field $field1 (ref $empty))
+ (field $field2 (ref $empty))))
+
+ (func (export "run")
+ (local $object (ref $thing))
+
+ struct.new $empty
+ struct.new $empty
+ struct.new $thing
+
+ local.tee $object
+ struct.get $thing $field1
+ drop
+
+ local.get $object
+ struct.get $thing $field2
+ drop))
+
+(assert_return (invoke "run"))
diff --git a/tests/misc_testsuite/gc/table-init-doesnt-leak.wast b/tests/misc_testsuite/gc/table-init-doesnt-leak.wast
new file mode 100644
index 0000000000..492873af8f
--- /dev/null
+++ b/tests/misc_testsuite/gc/table-init-doesnt-leak.wast
@@ -0,0 +1,24 @@
+;;! gc = true
+;;! bulk_memory = true
+;;! flags = """
+;;! -O memory-may-move=n
+;;! -O memory-reservation=65536
+;;! -O memory-reservation-for-growth=0
+;;! """
+
+(module
+ (table 1 arrayref)
+
+ (type $a (array i31ref))
+
+ (elem $e arrayref
+ (array.new $a (ref.i31 (i32.const 0)) (i32.const 200)))
+
+ (func (export "run")
+ (local $i i32)
+ (loop $l
+ (table.init $e (i32.const 0) (i32.const 0) (i32.const 1))
+ (local.set $i (i32.add (local.get $i) (i32.const 1)))
+ (br_if $l (i32.lt_u (local.get $i) (i32.const 200))))))
+
+(assert_return (invoke "run"))
diff --git a/tests/misc_testsuite/imported-memory-larger-than-reservation.wast b/tests/misc_testsuite/imported-memory-larger-than-reservation.wast
new file mode 100644
index 0000000000..695b4af1ec
--- /dev/null
+++ b/tests/misc_testsuite/imported-memory-larger-than-reservation.wast
@@ -0,0 +1,30 @@
+;;! memory64 = true
+;;! multi_memory = true
+;;! flags = "-O memory-reservation=65536 -O memory-may-move=n"
+
+;; An imported memory may be larger than both the importer's declared minimum
+;; and the memory reservation. Accesses within its actual size must succeed,
+;; even past the importer's minimum and the reservation.
+(module $m
+ (memory (export "m32") 4)
+ (memory (export "m64") i64 4)
+ (data (memory 0) (i32.const 262143) "\01")
+ (data (memory 1) (i64.const 262143) "\02"))
+(register "m" $m)
+
+(module
+ (import "m" "m32" (memory 1))
+ (import "m" "m64" (memory i64 1))
+ (func (export "load32") (param i32) (result i32)
+ (i32.load8_u 0 (local.get 0)))
+ (func (export "load64") (param i64) (result i32)
+ (i32.load8_u 1 offset=1 (local.get 0))))
+
+(assert_return (invoke "load32" (i32.const 0x20000)) (i32.const 0))
+(assert_return (invoke "load32" (i32.const 262143)) (i32.const 1))
+(assert_return (invoke "load64" (i64.const 0x20000)) (i32.const 0))
+(assert_return (invoke "load64" (i64.const 262142)) (i32.const 2))
+
+;; Accesses past the actual memory's size must still trap.
+(assert_trap (invoke "load32" (i32.const 262144)) "out of bounds memory access")
+(assert_trap (invoke "load64" (i64.const 262143)) "out of bounds memory access")
diff --git a/tests/misc_testsuite/memory-minimum-larger-than-reservation.wast b/tests/misc_testsuite/memory-minimum-larger-than-reservation.wast
new file mode 100644
index 0000000000..96339d7f71
--- /dev/null
+++ b/tests/misc_testsuite/memory-minimum-larger-than-reservation.wast
@@ -0,0 +1,25 @@
+;;! flags = "-O memory-reservation=0 -O memory-may-move=n"
+
+;; When a memory's minimum size exceeds the memory reservation, the runtime
+;; sizes the allocation from the minimum, so compilers must not treat the
+;; reservation as an upper bound on accessible memory. Accesses still trap past
+;; the minimum.
+(module
+ (memory 2)
+ (func (export "store") (param i32 i32)
+ (i32.store (local.get 0) (local.get 1)))
+ (func (export "load") (param i32) (result i32)
+ (i32.load (local.get 0)))
+ (func (export "load-offset") (param i32) (result i32)
+ (i32.load offset=70000 (local.get 0))))
+
+(assert_return (invoke "store" (i32.const 0) (i32.const 42)))
+(assert_return (invoke "load" (i32.const 0)) (i32.const 42))
+(assert_return (invoke "store" (i32.const 70000) (i32.const 7)))
+(assert_return (invoke "load-offset" (i32.const 0)) (i32.const 7))
+(assert_return (invoke "load" (i32.const 131068)) (i32.const 0))
+
+;; Accesses past the minimum size must still trap.
+(assert_trap (invoke "load" (i32.const 131069)) "out of bounds memory access")
+(assert_trap (invoke "load-offset" (i32.const 61069))
+ "out of bounds memory access")
diff --git a/tests/misc_testsuite/memory-reservation-exact.wast b/tests/misc_testsuite/memory-reservation-exact.wast
new file mode 100644
index 0000000000..4b609d4785
--- /dev/null
+++ b/tests/misc_testsuite/memory-reservation-exact.wast
@@ -0,0 +1,17 @@
+;;! flags = "-O memory-reservation=65536"
+
+;; The memory is exactly the size of the memory reservation, so every valid
+;; address must pass Cranelift's bounds checks. This catches off-by-one errors
+;; in static-heap bounds checks.
+(module
+ (memory 1 1)
+ (func (export "run")
+ (local $i i32)
+ (loop
+ (if (i32.eq (local.get $i) (i32.const 65536))
+ (then (return)))
+ (drop (i32.load8_u (local.get $i)))
+ (local.set $i (i32.add (local.get $i) (i32.const 1)))
+ br 0)))
+
+(assert_return (invoke "run"))
diff --git a/tests/misc_testsuite/stack-switching/gc-ref-result-on-operand-stack.wast b/tests/misc_testsuite/stack-switching/gc-ref-result-on-operand-stack.wast
new file mode 100644
index 0000000000..ee73d6a567
--- /dev/null
+++ b/tests/misc_testsuite/stack-switching/gc-ref-result-on-operand-stack.wast
@@ -0,0 +1,41 @@
+;;! stack_switching = true
+;;! gc = true
+;;! bulk_memory = true
+;;! flags = "-C collector=copying -O gc-zeal-alloc-counter=1"
+
+;; https://github.com/bytecodealliance/wasmtime/issues/13750
+;;
+;; A GC reference returned through a continuation's result must keep its
+;; stack-map entry while it is live on the operand stack across later GC
+;; safepoints.
+(module
+ (type $S (struct (field $x i32)))
+ (type $A (array i64))
+ (type $ft (func (result (ref $S))))
+ (type $ct (cont $ft))
+
+ (func $target (result (ref $S))
+ (struct.new $S (i32.const 0x12345678)))
+ (elem declare func $target)
+
+ (func (export "run") (result i32)
+ (local $k (ref null $ct))
+ (local $i i32)
+ (local.set $k (cont.new $ct (ref.func $target)))
+
+ ;; Keep the continuation's GC-reference result on the operand stack,
+ ;; rather than storing it in a GC-typed local.
+ (resume $ct (local.get $k))
+
+ ;; Force collections while that operand-stack value is the only live
+ ;; reference to the struct.
+ (local.set $i (i32.const 0))
+ (loop $again
+ (drop (array.new_default $A (i32.const 256)))
+ (local.set $i (i32.add (local.get $i) (i32.const 1)))
+ (br_if $again
+ (i32.lt_u (local.get $i) (i32.const 2000))))
+
+ (struct.get $S $x)))
+
+(assert_return (invoke "run") (i32.const 0x12345678))