Skip to content

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

Disable using `memset` on tables (#14328)

Alex Crichton3c310e801e8b
diff --git a/crates/cranelift/src/func_environ.rs b/crates/cranelift/src/func_environ.rs
index a2a03e7df7..687570e9d0 100644
--- a/crates/cranelift/src/func_environ.rs
+++ b/crates/cranelift/src/func_environ.rs
@@ -6532,7 +6532,7 @@ impl CheckedEntity {
CheckedEntity::Elem(_) => false,
// Tables that are lazily initialized can't be memset because the
// initialized bit needs to be set when storing values.
- CheckedEntity::Table { .. } => !env.tunables.table_lazy_init,
+ CheckedEntity::Table { .. } => false,
}
}
}
diff --git a/tests/all/gc.rs b/tests/all/gc.rs
index c432c48fbf..97c224cc2a 100644
--- a/tests/all/gc.rs
+++ b/tests/all/gc.rs
@@ -4207,3 +4207,45 @@ fn gc_during_epoch(wat: &str) -> Result<()> {
}
Ok(())
}
+
+#[test]
+#[cfg_attr(miri, ignore)]
+fn table_fill_null_barriers_ok() -> Result<()> {
+ for collector in [Collector::Copying, Collector::DeferredReferenceCounting] {
+ eprintln!("collector: {collector:?}");
+ let engine = Engine::new(Config::new().collector(collector).table_lazy_init(false))?;
+ let module = Module::new(
+ &engine,
+ r#"
+ (module
+ (table $t (export "t") 1 (ref null extern))
+ (func (export "fill") (param i32) (param i32)
+ (table.fill $t (local.get 0) (ref.null extern) (local.get 1)))
+ )
+ "#,
+ )?;
+
+ let mut store = Store::new(&engine, ());
+ let instance = Instance::new(&mut store, &module, &[])?;
+ let fill = instance.get_typed_func::<(u32, u32), ()>(&mut store, "fill")?;
+ let table = instance.get_table(&mut store, "t").unwrap();
+
+ let flag = Arc::new(AtomicBool::new(false));
+
+ {
+ let mut scope = RootScope::new(&mut store);
+ let r = ExternRef::new(&mut scope, SetFlagOnDrop(flag.clone()))?;
+ table.set(&mut scope, 0, r.into())?;
+ }
+
+ assert!(!flag.load(SeqCst));
+ store.gc(None)?;
+ assert!(!flag.load(SeqCst));
+
+ fill.call(&mut store, (0, 1))?;
+ store.gc(None)?;
+ assert!(flag.load(SeqCst));
+ }
+
+ Ok(())
+}