diff options
author | Alon Zakai <azakai@google.com> | 2023-08-31 15:41:03 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-31 15:41:03 -0700 |
commit | 126d4fab3e00f003a06dac23f96aa70cbb75aa67 (patch) | |
tree | 21a12fe65130861c7d53b80aba93ba21c3392c27 | |
parent | 0d3c2eeb634913643f2cade4b5d738962b2308c2 (diff) | |
download | binaryen-126d4fab3e00f003a06dac23f96aa70cbb75aa67.tar.gz binaryen-126d4fab3e00f003a06dac23f96aa70cbb75aa67.tar.bz2 binaryen-126d4fab3e00f003a06dac23f96aa70cbb75aa67.zip |
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
-rw-r--r-- | src/wasm-traversal.h | 7 | ||||
-rw-r--r-- | test/lit/debug/replace-keep.wat | 32 |
2 files changed, 38 insertions, 1 deletions
diff --git a/src/wasm-traversal.h b/src/wasm-traversal.h index 80378242a..212ded365 100644 --- a/src/wasm-traversal.h +++ b/src/wasm-traversal.h @@ -124,7 +124,12 @@ struct Walker : public VisitorType { // Copy debug info, if present. if (currFunction) { auto& debugLocations = currFunction->debugLocations; - if (!debugLocations.empty()) { + // Early exit if there is no debug info at all. Also, leave if we already + // have debug info on the new expression, which we don't want to trample: + // if there is no debug info we do want to copy, as a replacement + // operation suggests the new code plays the same role (it is an optimized + // version of the old), but if the code is already annotated, trust that. + if (!debugLocations.empty() && !debugLocations.count(expression)) { auto* curr = getCurrent(); auto iter = debugLocations.find(curr); if (iter != debugLocations.end()) { diff --git a/test/lit/debug/replace-keep.wat b/test/lit/debug/replace-keep.wat index 1418d13dd..cfd8e1ced 100644 --- a/test/lit/debug/replace-keep.wat +++ b/test/lit/debug/replace-keep.wat @@ -37,4 +37,36 @@ ) ) ) + + ;; CHECK: (func $test-no-trample + ;; CHECK-NEXT: (local $temp i32) + ;; CHECK-NEXT: [none] ;;@ src.cpp:300:3 + ;; CHECK-NEXT: [none](block + ;; CHECK-NEXT: [none] ;;@ src.cpp:400:4 + ;; CHECK-NEXT: (call $test) + ;; CHECK-NEXT: [none] ;;@ src.cpp:200:2 + ;; CHECK-NEXT: (local.set $temp + ;; CHECK-NEXT: [i32] ;;@ src.cpp:500:5 + ;; CHECK-NEXT: (i32.const 1) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) ;; end block + ;; CHECK-NEXT: ;;@ src.cpp:200:2 + ;; CHECK-NEXT: ) + (func $test-no-trample + (local $temp i32) + + ;; As above, but now the inner block has debug info (300), which should not + ;; be trampled as it is moved outside. + + ;;@ src.cpp:200:2 + (local.set $temp + ;;@ src.cpp:300:3 + (block (result i32) + ;;@ src.cpp:400:4 + (call $test) + ;;@ src.cpp:500:5 + (i32.const 1) + ) + ) + ) ) |