Skip to content

Commit 58de22c

Browse files
authored
Do not copy function annotations when copying expressions (#8512)
When copying expressions from one function to another, we previously also copied the function-level annotations from the source function to the destination. This is not correct, and caused a bug where the @binaryen.removable.if.unused annotation was copied from an inlined function to its caller, resulting in side effects being dropped. Fix the problem by moving responsibility for copying function annotations from `copyBetweenFunctions` to `copyFunctionWithoutAdd`. Fixes #8509.
1 parent 8f85446 commit 58de22c

3 files changed

Lines changed: 35 additions & 5 deletions

File tree

src/ir/metadata.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ void copyBetweenFunctions(Expression* origin,
4444
Function* originFunc,
4545
Function* copyFunc) {
4646
if (originFunc->debugLocations.empty() &&
47-
originFunc->codeAnnotations.empty() &&
48-
originFunc->funcAnnotations.empty()) {
47+
originFunc->codeAnnotations.empty()) {
4948
// Nothing to copy.
5049
return;
5150
}
@@ -75,9 +74,6 @@ void copyBetweenFunctions(Expression* origin,
7574
}
7675
}
7776
}
78-
79-
// Also copy function-level annotations.
80-
copyFunc->funcAnnotations = originFunc->funcAnnotations;
8177
}
8278

8379
#pragma GCC diagnostic push

src/ir/module-utils.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ copyFunctionWithoutAdd(Function* func,
7373
ret->localIndices = func->localIndices;
7474
ret->body = ExpressionManipulator::copy(func->body, out);
7575
metadata::copyBetweenFunctions(func->body, ret->body, func, ret.get());
76+
ret->funcAnnotations = func->funcAnnotations;
7677
ret->prologLocation = func->prologLocation;
7778
ret->epilogLocation = func->epilogLocation;
7879
// Update file indices if needed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
;; NOTE: Assertions have been generated by update_lit_checks.py and should not be edited.
2+
3+
;; RUN: wasm-opt %s --inlining-optimizing -S -o - | filecheck %s
4+
5+
(module
6+
;; CHECK: (import "" "" (func $import (param i32)))
7+
(import "" "" (func $import (param i32)))
8+
;; CHECK: (export "test" (func $test))
9+
(export "test" (func $test))
10+
;; CHECK: (func $test
11+
;; CHECK-NEXT: (call $import
12+
;; CHECK-NEXT: (i32.const 0)
13+
;; CHECK-NEXT: )
14+
;; CHECK-NEXT: )
15+
(func $test
16+
(call $main)
17+
)
18+
(func $main
19+
(call $print)
20+
)
21+
(func $print
22+
;; $print should not inherit the removable.if.unused attribute from the
23+
;; inlined call to $removable. (If it did, then we would incorrectly remove
24+
;; the call to the import.)
25+
(call $import
26+
(call $removable)
27+
)
28+
)
29+
(@binaryen.removable.if.unused)
30+
(func $removable (result i32)
31+
(i32.const 0)
32+
)
33+
)

0 commit comments

Comments
 (0)