Fixes element instance for imported global func ref (#2141)

Signed-off-by: Takeshi Yoneda <t.y.mathetake@gmail.com>
This commit is contained in:
Takeshi Yoneda
2024-03-08 13:19:15 +09:00
committed by GitHub
parent ac052ab84a
commit 9da95bd4b1
4 changed files with 22 additions and 6 deletions

View File

@@ -1065,8 +1065,15 @@ func Test2136(t *testing.T) {
}
func Test2137(t *testing.T) {
r := wazero.NewRuntime(context.Background())
_, err := r.CompileModule(ctx, getWasmBinary(t, "2137"))
require.NoError(t, err)
require.NoError(t, r.Close(ctx))
if !platform.CompilerSupported() {
return
}
nodiff.RequireNoDiffT(t, getWasmBinary(t, "2137"), true, true)
}
func Test2140(t *testing.T) {
if !platform.CompilerSupported() {
return
}
nodiff.RequireNoDiffT(t, getWasmBinary(t, "2140"), true, true)
}

Binary file not shown.

View File

@@ -0,0 +1,4 @@
(module
(import "hh" "" (global (;0;) funcref))
(elem (;0;) funcref (ref.null func) (ref.null func) (ref.null func) (global.get 0) (ref.null func))
)

View File

@@ -179,8 +179,13 @@ func (m *ModuleInstance) buildElementInstances(elements []ElementSegment) {
inst := make([]Reference, len(inits))
m.ElementInstances[i] = inst
for j, idx := range inits {
if idx != ElementInitNullReference {
inst[j] = m.Engine.FunctionInstanceReference(idx)
if index, ok := unwrapElementInitGlobalReference(idx); ok {
global := m.Globals[index]
inst[j] = Reference(global.Val)
} else {
if idx != ElementInitNullReference {
inst[j] = m.Engine.FunctionInstanceReference(idx)
}
}
}
}