Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/ir/metadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ void copyBetweenFunctions(Expression* origin,
Function* originFunc,
Function* copyFunc) {
if (originFunc->debugLocations.empty() &&
originFunc->codeAnnotations.empty()) {
originFunc->codeAnnotations.empty() &&
originFunc->funcAnnotations.empty()) {
// Nothing to copy.
return;
}
Expand Down Expand Up @@ -75,7 +76,7 @@ void copyBetweenFunctions(Expression* origin,
}
}

// Also copy function-level annotations, if any.
// Also copy function-level annotations.
copyFunc->funcAnnotations = originFunc->funcAnnotations;
}

Expand Down
3 changes: 3 additions & 0 deletions src/wasm.h
Original file line number Diff line number Diff line change
Expand Up @@ -2279,6 +2279,9 @@ struct CodeAnnotation {
return removableIfUnused == other.removableIfUnused &&
jsCalled == other.jsCalled && idempotent == other.idempotent;
}

// Checks if no annotation is actually set.
bool empty() { return *this == CodeAnnotation(); }
};

class Function : public Importable {
Expand Down
44 changes: 44 additions & 0 deletions test/lit/merge/annotations-func-only.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited.

;; RUN: wasm-merge %s first %s.second second -all -S -o - | filecheck %s

;; Test that we handle code annotations properly when they appear *only* in
;; functions (not code). Both the first and second wasm files have an annotation
;; that should be preserved.

(module
;; CHECK: (type $0 (func))

;; CHECK: (export "first" (func $first))

;; CHECK: (export "second" (func $second))

;; CHECK: (@binaryen.js.called)
;; CHECK-NEXT: (func $first (type $0)
;; CHECK-NEXT: (if
;; CHECK-NEXT: (i32.const 0)
;; CHECK-NEXT: (then
;; CHECK-NEXT: (return)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: )
(@binaryen.js.called)
(func $first (export "first")
(if
(i32.const 0)
(then
(return)
)
)
)
)

;; CHECK: (@binaryen.js.called)
;; CHECK-NEXT: (func $second (type $0)
;; CHECK-NEXT: (if
;; CHECK-NEXT: (i32.const 0)
;; CHECK-NEXT: (then
;; CHECK-NEXT: (return)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: )
12 changes: 12 additions & 0 deletions test/lit/merge/annotations-func-only.wat.second
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
(module
(@binaryen.js.called)
(func $second (export "second")
(if
(i32.const 0)
(then
(return)
)
)
)
)

Loading