Skip to content

Commit f27ff3e

Browse files
authored
Fix Branch Hinting iostream printing (#7603)
The code saved and restored std::cout, not the current stream... and the current stream is std::cout in most tests, so this went unnoticed. Printing from wasm-dis works otherwise apparently, and the bug showed up there.
1 parent f8531ef commit f27ff3e

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

src/passes/Print.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2679,11 +2679,11 @@ void PrintSExpression::printCodeAnnotations(Expression* curr) {
26792679
if (annotation.inline_) {
26802680
Colors::grey(o);
26812681
std::ofstream saved;
2682-
saved.copyfmt(std::cout);
2682+
saved.copyfmt(o);
26832683
o << "(@" << Annotations::InlineHint << " \"\\" << std::hex
26842684
<< std::setfill('0') << std::setw(2) << int(*annotation.inline_)
26852685
<< "\")\n";
2686-
std::cout.copyfmt(saved);
2686+
o.copyfmt(saved);
26872687
restoreNormalColor(o);
26882688
doIndent(o, indent);
26892689
}

test/lit/branch-hinting-printing.wast

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
;; The branch hint should not cause the later constant to print incorrectly
2+
;; (branch hints are printed in hex, and we should clear that state so later
3+
;; things are not affected).
4+
5+
(module
6+
(type $0 (func))
7+
(func $0 (type $0)
8+
(@metadata.code.inline "\00")
9+
(call $0)
10+
)
11+
(func $1 (type $0)
12+
(drop
13+
(i32.const -18428)
14+
)
15+
)
16+
)
17+
18+
;; RUN: wasm-opt %s -o %t.wasm -g
19+
;; RUN: wasm-dis %t.wasm | filecheck %s
20+
21+
;; CHECK: (i32.const -18428)

0 commit comments

Comments
 (0)