From 34da42d55a465e40e914c559077bab53a076e875 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Wed, 15 Oct 2025 11:12:43 -0700 Subject: [PATCH] fix but why does fuzzer not find? --- src/tools/wasm-merge.cpp | 4 +++ test/lit/merge/global_subtyping.wat | 42 ++++++++++++++++++++++ test/lit/merge/global_subtyping.wat.second | 14 ++++++++ 3 files changed, 60 insertions(+) create mode 100644 test/lit/merge/global_subtyping.wat create mode 100644 test/lit/merge/global_subtyping.wat.second diff --git a/src/tools/wasm-merge.cpp b/src/tools/wasm-merge.cpp index bfce9f0cdc2..149633c6958 100644 --- a/src/tools/wasm-merge.cpp +++ b/src/tools/wasm-merge.cpp @@ -568,6 +568,10 @@ void updateTypes(Module& wasm) { return std::make_unique(); } + void visitGlobalGet(GlobalGet* curr) { + curr->type = getModule()->getGlobal(curr->name)->type; + } + void visitRefFunc(RefFunc* curr) { curr->finalize(getModule()->getFunction(curr->func)->type); } diff --git a/test/lit/merge/global_subtyping.wat b/test/lit/merge/global_subtyping.wat new file mode 100644 index 00000000000..0900fe8a399 --- /dev/null +++ b/test/lit/merge/global_subtyping.wat @@ -0,0 +1,42 @@ +;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited. + +;; RUN: wasm-merge %s primary %s.second secondary --skip-export-conflicts -all -S -o - | filecheck %s + +;; Export a global with a subtype. It is imported using the supertype, and +;; after we merge, the type must be updated, including in the global.get from +;; the second module (that goes from super to sub). +(module + ;; CHECK: (type $super (sub (func))) + (type $super (sub (func))) + ;; CHECK: (type $sub (sub final $super (func))) + (type $sub (sub final $super (func))) + + ;; CHECK: (type $2 (func)) + + ;; CHECK: (global $sub (ref $sub) (ref.func $sub)) + (global $sub (ref $sub) (ref.func $sub)) + + ;; CHECK: (export "sub" (global $sub)) + (export "sub" (global $sub)) + + ;; CHECK: (export "second-user" (func $second-user)) + + ;; CHECK: (func $sub (type $sub) + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (global.get $sub) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + (func $sub (type $sub) + (drop + (global.get $sub) + ) + ) +) + +;; CHECK: (func $second-user (type $2) +;; CHECK-NEXT: (drop +;; CHECK-NEXT: (block (result (ref $sub)) +;; CHECK-NEXT: (global.get $sub) +;; CHECK-NEXT: ) +;; CHECK-NEXT: ) +;; CHECK-NEXT: ) diff --git a/test/lit/merge/global_subtyping.wat.second b/test/lit/merge/global_subtyping.wat.second new file mode 100644 index 00000000000..eb948e0d85d --- /dev/null +++ b/test/lit/merge/global_subtyping.wat.second @@ -0,0 +1,14 @@ +(module + (type $second-super (sub (func))) + + (import "primary" "sub" (global $import (ref $second-super))) + + (func $second-user (export "second-user") + (drop + (block (result (ref $second-super)) + (global.get $import) + ) + ) + ) +) +