Skip to content

Commit fd5e86e

Browse files
authored
[CodeAnnotations] Copy function-level annotations, fixing wasm-merge (#8345)
We copied expression annotations but not function ones. As a result, wasm-merge would copy functions between modules and drop their hints.
1 parent 74a471c commit fd5e86e

File tree

3 files changed

+65
-0
lines changed

3 files changed

+65
-0
lines changed

src/ir/metadata.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ void copyBetweenFunctions(Expression* origin,
7474
}
7575
}
7676
}
77+
78+
// Also copy function-level annotations, if any.
79+
auto iter = originAnnotations.find(nullptr);
80+
if (iter != originAnnotations.end()) {
81+
copyAnnotations[nullptr] = iter->second;
82+
}
7783
}
7884

7985
#pragma GCC diagnostic push

test/lit/merge/annotations.wat

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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+
;; Test that we handle code annotations properly. Both the first and second
6+
;; wasm files have annotations that should be preserved.
7+
8+
(module
9+
;; CHECK: (type $0 (func))
10+
11+
;; CHECK: (export "first" (func $first))
12+
13+
;; CHECK: (export "second" (func $second))
14+
15+
;; CHECK: (@binaryen.js.called)
16+
;; CHECK-NEXT: (func $first (type $0)
17+
;; CHECK-NEXT: (@metadata.code.branch_hint "\00")
18+
;; CHECK-NEXT: (if
19+
;; CHECK-NEXT: (i32.const 0)
20+
;; CHECK-NEXT: (then
21+
;; CHECK-NEXT: (return)
22+
;; CHECK-NEXT: )
23+
;; CHECK-NEXT: )
24+
;; CHECK-NEXT: )
25+
(@binaryen.js.called)
26+
(func $first (export "first")
27+
(@metadata.code.branch_hint "\00")
28+
(if
29+
(i32.const 0)
30+
(then
31+
(return)
32+
)
33+
)
34+
)
35+
)
36+
37+
;; CHECK: (@binaryen.js.called)
38+
;; CHECK-NEXT: (func $second (type $0)
39+
;; CHECK-NEXT: (@metadata.code.branch_hint "\01")
40+
;; CHECK-NEXT: (if
41+
;; CHECK-NEXT: (i32.const 0)
42+
;; CHECK-NEXT: (then
43+
;; CHECK-NEXT: (return)
44+
;; CHECK-NEXT: )
45+
;; CHECK-NEXT: )
46+
;; CHECK-NEXT: )
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
(module
2+
(@binaryen.js.called)
3+
(func $second (export "second")
4+
(@metadata.code.branch_hint "\01")
5+
(if
6+
(i32.const 0)
7+
(then
8+
(return)
9+
)
10+
)
11+
)
12+
)
13+

0 commit comments

Comments
 (0)