Skip to content

Commit 874fc08

Browse files
authored
fix wasm-builder set_global creation - we must call finalize, as the value may be unreachable (#1216)
1 parent fcbe7bf commit 874fc08

File tree

3 files changed

+83
-0
lines changed

3 files changed

+83
-0
lines changed

src/wasm-builder.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ class Builder {
192192
auto* ret = allocator.alloc<SetGlobal>();
193193
ret->name = name;
194194
ret->value = value;
195+
ret->finalize();
195196
return ret;
196197
}
197198
Load* makeLoad(unsigned bytes, bool signed_, uint32_t offset, unsigned align, Expression *ptr, WasmType type) {

test/passes/O3_inlining.txt

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
(module
2+
(type $0 (func))
3+
(type $1 (func (param i32)))
4+
(type $2 (func (param f32 i32 i32) (result i32)))
5+
(global $global$0 (mut f64) (f64.const -32768))
6+
(global $global$1 (mut i32) (i32.const 100))
7+
(memory $0 1 1)
8+
(export "func_217" (func $1))
9+
(func $1 (type $1) (param $0 i32)
10+
(block $__inlined_func$0
11+
(block
12+
(if
13+
(get_global $global$1)
14+
(unreachable)
15+
)
16+
(set_global $global$1
17+
(i32.const 0)
18+
)
19+
(block $label$2
20+
(set_global $global$0
21+
(block
22+
(br_if $label$2
23+
(if (result i32)
24+
(i32.load16_u
25+
(i32.const 3)
26+
)
27+
(i32.const 1)
28+
(i32.const 0)
29+
)
30+
)
31+
(unreachable)
32+
)
33+
)
34+
)
35+
)
36+
)
37+
)
38+
)

test/passes/O3_inlining.wast

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
(module
2+
(global $global$0 (mut f64) (f64.const -32768))
3+
(global $global$1 (mut i32) (i32.const 100))
4+
(memory $0 1 1)
5+
(export "func_217" (func $1))
6+
(func $0
7+
(if
8+
(get_global $global$1)
9+
(unreachable)
10+
)
11+
(set_global $global$1
12+
(i32.const 0)
13+
)
14+
(block $label$2
15+
(set_global $global$0
16+
(block $label$3 (result f64)
17+
(br_if $label$2
18+
(if (result i32)
19+
(i32.load16_u offset=3
20+
(i32.const 0)
21+
)
22+
(i32.const 1)
23+
(i32.const 0)
24+
)
25+
)
26+
(unreachable)
27+
)
28+
)
29+
)
30+
)
31+
(func $1 (param $var$0 i32)
32+
(drop
33+
(call $2
34+
(f32.const 1)
35+
(i32.const 1)
36+
(i32.const 0)
37+
)
38+
)
39+
)
40+
(func $2 (param $var$0 f32) (param $var$1 i32) (param $var$2 i32) (result i32)
41+
(call $0)
42+
(i32.const 0)
43+
)
44+
)

0 commit comments

Comments
 (0)