Skip to content
Open
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
3 changes: 2 additions & 1 deletion src/tools/wasm-reduce/wasm-reduce.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1102,6 +1102,7 @@ struct Reducer
auto* block =
ChildLocalizer(curr, getFunction(), *getModule(), getPassOptions())
.getChildrenReplacement();
auto originalType = curr->type;
auto* replacement = builder.replaceWithIdenticalType(curr);
// We may have failed to come up with a replacement (e.g. for
// non-nullable references), so manually add an `unreachable` in that
Expand All @@ -1110,7 +1111,7 @@ struct Reducer
replacement = builder.makeUnreachable();
}
block->list.push_back(replacement);
block->type = curr->type;
block->type = originalType;
replaceCurrent(block);
}
void visitRefFunc(RefFunc* curr) {
Expand Down
19 changes: 19 additions & 0 deletions test/lit/wasm-reduce/reduce-validation-error.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
;; This is a regression test for a crash in wasm-reduce where in-place mutation
;; of a Call node during replaceWithIdenticalType caused the replacement block
;; type to be set incorrectly to nullref instead of the original type, leading
;; to a validation error.

;; RUN: wasm-reduce %s -t %t.t.wast -w %t.w.wast \
;; RUN: --command='wasm-opt %t.t.wast -all --fuzz-exec'

(module
(func $to_remove (result anyref)
(ref.null none)
)

(func $main (export "main") (result anyref)
;; This will be replaced with a nullref. This should not cause validation
;; failures and cause wasm-reduce to crash.
(call $to_remove)
)
)
Loading