Skip to content

Commit 126d4fa

Browse files
authored
DebugInfo: Don't trample in replaceCurrent() (#5915)
Copy the old expression's debug info if the new has none. But if the new has its own, trust that. Followup to #5914
1 parent 0d3c2ee commit 126d4fa

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

src/wasm-traversal.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,12 @@ struct Walker : public VisitorType {
124124
// Copy debug info, if present.
125125
if (currFunction) {
126126
auto& debugLocations = currFunction->debugLocations;
127-
if (!debugLocations.empty()) {
127+
// Early exit if there is no debug info at all. Also, leave if we already
128+
// have debug info on the new expression, which we don't want to trample:
129+
// if there is no debug info we do want to copy, as a replacement
130+
// operation suggests the new code plays the same role (it is an optimized
131+
// version of the old), but if the code is already annotated, trust that.
132+
if (!debugLocations.empty() && !debugLocations.count(expression)) {
128133
auto* curr = getCurrent();
129134
auto iter = debugLocations.find(curr);
130135
if (iter != debugLocations.end()) {

test/lit/debug/replace-keep.wat

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,36 @@
3737
)
3838
)
3939
)
40+
41+
;; CHECK: (func $test-no-trample
42+
;; CHECK-NEXT: (local $temp i32)
43+
;; CHECK-NEXT: [none] ;;@ src.cpp:300:3
44+
;; CHECK-NEXT: [none](block
45+
;; CHECK-NEXT: [none] ;;@ src.cpp:400:4
46+
;; CHECK-NEXT: (call $test)
47+
;; CHECK-NEXT: [none] ;;@ src.cpp:200:2
48+
;; CHECK-NEXT: (local.set $temp
49+
;; CHECK-NEXT: [i32] ;;@ src.cpp:500:5
50+
;; CHECK-NEXT: (i32.const 1)
51+
;; CHECK-NEXT: )
52+
;; CHECK-NEXT: ) ;; end block
53+
;; CHECK-NEXT: ;;@ src.cpp:200:2
54+
;; CHECK-NEXT: )
55+
(func $test-no-trample
56+
(local $temp i32)
57+
58+
;; As above, but now the inner block has debug info (300), which should not
59+
;; be trampled as it is moved outside.
60+
61+
;;@ src.cpp:200:2
62+
(local.set $temp
63+
;;@ src.cpp:300:3
64+
(block (result i32)
65+
;;@ src.cpp:400:4
66+
(call $test)
67+
;;@ src.cpp:500:5
68+
(i32.const 1)
69+
)
70+
)
71+
)
4072
)

0 commit comments

Comments
 (0)