Skip to content

Commit 4084d6e

Browse files
authored
Fix copying of globals (#1854)
This broke when we refactored imports, as now Global has two more fields. Test is on --func-metrics, which depends on copying to compute some things.
1 parent 6f435bc commit 4084d6e

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

src/ir/module-utils.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ inline Global* copyGlobal(Global* global, Module& out) {
9292
ret->name = global->name;
9393
ret->type = global->type;
9494
ret->mutable_ = global->mutable_;
95+
ret->module = global->module;
96+
ret->base = global->base;
9597
if (global->imported()) {
9698
ret->init = nullptr;
9799
} else {

test/passes/func-metrics.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,3 +199,23 @@ start: func_a
199199
(call $waka)
200200
)
201201
)
202+
global
203+
[funcs] : 1
204+
[imports] : 1
205+
[total] : 1
206+
global.get : 1
207+
func: 0
208+
[binary-bytes] : 4
209+
[total] : 1
210+
global.get : 1
211+
export: stackSave (0)
212+
[removable-bytes-without-it]: 74
213+
(module
214+
(type $0 (func (result i32)))
215+
(import "env" "STACKTOP" (global $gimport$0 i32))
216+
(global $global$0 (mut i32) (global.get $gimport$0))
217+
(export "stackSave" (func $0))
218+
(func $0 (; 0 ;) (type $0) (result i32)
219+
(global.get $global$0)
220+
)
221+
)

test/passes/func-metrics.wast

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,4 +122,13 @@
122122
(call $waka)
123123
)
124124
)
125+
(module ;; various globals
126+
(type $0 (func (result i32)))
127+
(import "env" "STACKTOP" (global $gimport$0 i32))
128+
(global $global$0 (mut i32) (global.get $gimport$0))
129+
(export "stackSave" (func $0))
130+
(func $0 (; 0 ;) (type $0) (result i32)
131+
(global.get $global$0)
132+
)
133+
)
125134

0 commit comments

Comments
 (0)