Skip to content

Commit 5736859

Browse files
committed
Address review: use getGlobal, add test for nested inlining
1 parent dea3473 commit 5736859

3 files changed

Lines changed: 40 additions & 2 deletions

File tree

‎src/tools/wasm-merge.cpp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -590,8 +590,8 @@ void fixTableInitializers() {
590590
struct Inliner : public PostWalker<Inliner> {
591591
bool inlined = false;
592592
void visitGlobalGet(GlobalGet* curr) {
593-
auto* global = getModule()->getGlobalOrNull(curr->name);
594-
if (global && !global->imported()) {
593+
auto* global = getModule()->getGlobal(curr->name);
594+
if (!global->imported()) {
595595
assert(global->init && !global->mutable_);
596596
replaceCurrent(ExpressionManipulator::copy(global->init, *getModule()));
597597
inlined = true;
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited.
2+
3+
;; RUN: wasm-merge %s first %s.second second -all -S -o - | filecheck %s
4+
5+
;; Like table-init.wat, but the global $g that the table initializer refers to
6+
;; is fused with a global whose initializer itself refers to another
7+
;; module-defined global, $a. Inlining $g exposes a reference to $a, which must
8+
;; be inlined as well, so verify that we keep inlining until the initializer
9+
;; refers to no module-defined globals.
10+
11+
(module
12+
;; CHECK: (type $f (func))
13+
(type $f (func))
14+
15+
(global $g (import "second" "g") (ref $f))
16+
17+
;; CHECK: (global $a (ref $f) (ref.func $h))
18+
19+
;; CHECK: (global $g_1 (ref $f) (global.get $a))
20+
21+
;; CHECK: (table $t 3 funcref (ref.func $h))
22+
(table $t (export "t") 3 funcref (global.get $g))
23+
)
24+
;; CHECK: (export "t" (table $t))
25+
26+
;; CHECK: (export "g" (global $g_1))
27+
28+
;; CHECK: (func $h (type $f)
29+
;; CHECK-NEXT: )
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
(module
2+
(type $f (func))
3+
4+
(func $h)
5+
6+
(global $a (ref $f) (ref.func $h))
7+
8+
(global $g (export "g") (ref $f) (global.get $a))
9+
)

0 commit comments

Comments
 (0)