Skip to content

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

Exceptions: global.get from external or table init: null exnref is not an anyref. (#11564)

Chris Fallin5906a5dc9120
diff --git a/crates/wasmtime/src/runtime/externals/global.rs b/crates/wasmtime/src/runtime/externals/global.rs
index ce87e26165..11d7d8427b 100644
--- a/crates/wasmtime/src/runtime/externals/global.rs
+++ b/crates/wasmtime/src/runtime/externals/global.rs
@@ -1,8 +1,8 @@
use crate::prelude::*;
use crate::runtime::vm::{self, VMGlobalDefinition, VMGlobalKind, VMOpaqueContext};
use crate::{
- AnyRef, AsContext, AsContextMut, ExternRef, Func, GlobalType, HeapType, Mutability, Ref,
- RootedGcRefImpl, Val, ValType,
+ AnyRef, AsContext, AsContextMut, ExnRef, ExternRef, Func, GlobalType, HeapType, Mutability,
+ Ref, RootedGcRefImpl, Val, ValType,
store::{AutoAssertNoGc, InstanceId, StoreId, StoreInstanceId, StoreOpaque},
trampoline::generate_global_export,
};
@@ -172,15 +172,21 @@ impl Global {
HeapType::NoExtern => Ref::Extern(None),
+ HeapType::Exn | HeapType::ConcreteExn(_) => definition
+ .as_gc_ref()
+ .map(|r| {
+ let r = store.clone_gc_ref(r);
+ ExnRef::from_cloned_gc_ref(store, r)
+ })
+ .into(),
+
HeapType::Any
| HeapType::Eq
| HeapType::I31
| HeapType::Struct
| HeapType::ConcreteStruct(_)
| HeapType::Array
- | HeapType::ConcreteArray(_)
- | HeapType::Exn
- | HeapType::ConcreteExn(_) => definition
+ | HeapType::ConcreteArray(_) => definition
.as_gc_ref()
.map(|r| {
let r = store.clone_gc_ref(r);
diff --git a/tests/misc_testsuite/issue11561.wast b/tests/misc_testsuite/issue11561.wast
new file mode 100644
index 0000000000..ab635c1505
--- /dev/null
+++ b/tests/misc_testsuite/issue11561.wast
@@ -0,0 +1,8 @@
+;;! exceptions = true
+;;! gc = true
+
+(module
+ (table $t 10 exnref)
+ (global $g exnref (ref.null exn))
+ (elem (table $t) (i32.const 0) exnref (global.get $g))
+)
diff --git a/tests/misc_testsuite/issue11563.wat b/tests/misc_testsuite/issue11563.wat
new file mode 100644
index 0000000000..7a0d2ec22f
--- /dev/null
+++ b/tests/misc_testsuite/issue11563.wat
@@ -0,0 +1,10 @@
+;;! gc = yes
+;;! exceptions = yes
+;;! function-references = yes
+
+(module $m
+ (global (export "") exnref (ref.null exn)))
+
+(module
+ (import "m" "" (global exnref))
+ (table 1 exnref (global.get 0)))