Skip to content

Commit c73011b

Browse files
authored
wasm-merge: Fix global.get types (#8015)
After merging they may get refined.
1 parent 1d97f47 commit c73011b

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed

src/tools/wasm-merge.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,10 @@ void updateTypes(Module& wasm) {
570570
return std::make_unique<Updater>();
571571
}
572572

573+
void visitGlobalGet(GlobalGet* curr) {
574+
curr->type = getModule()->getGlobal(curr->name)->type;
575+
}
576+
573577
void visitRefFunc(RefFunc* curr) {
574578
curr->finalize(getModule()->getFunction(curr->func)->type.getHeapType());
575579
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited.
2+
3+
;; RUN: wasm-merge %s primary %s.second secondary --skip-export-conflicts -all -S -o - | filecheck %s
4+
5+
;; Export a global with a subtype. It is imported using the supertype, and
6+
;; after we merge, the type must be updated, including in the global.get from
7+
;; the second module (that goes from super to sub).
8+
(module
9+
;; CHECK: (type $super (sub (func)))
10+
(type $super (sub (func)))
11+
;; CHECK: (type $sub (sub final $super (func)))
12+
(type $sub (sub final $super (func)))
13+
14+
;; CHECK: (type $2 (func))
15+
16+
;; CHECK: (global $sub (ref $sub) (ref.func $sub))
17+
(global $sub (ref $sub) (ref.func $sub))
18+
19+
;; CHECK: (export "sub" (global $sub))
20+
(export "sub" (global $sub))
21+
22+
;; CHECK: (export "second-user" (func $second-user))
23+
24+
;; CHECK: (func $sub (type $sub)
25+
;; CHECK-NEXT: (drop
26+
;; CHECK-NEXT: (global.get $sub)
27+
;; CHECK-NEXT: )
28+
;; CHECK-NEXT: )
29+
(func $sub (type $sub)
30+
(drop
31+
(global.get $sub)
32+
)
33+
)
34+
)
35+
36+
;; CHECK: (func $second-user (type $2)
37+
;; CHECK-NEXT: (drop
38+
;; CHECK-NEXT: (block (result (ref $sub))
39+
;; CHECK-NEXT: (global.get $sub)
40+
;; CHECK-NEXT: )
41+
;; CHECK-NEXT: )
42+
;; CHECK-NEXT: )
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
(module
2+
(type $second-super (sub (func)))
3+
4+
(import "primary" "sub" (global $import (ref $second-super)))
5+
6+
(func $second-user (export "second-user")
7+
(drop
8+
(block (result (ref $second-super))
9+
(global.get $import)
10+
)
11+
)
12+
)
13+
)
14+

0 commit comments

Comments
 (0)