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
7 changes: 7 additions & 0 deletions src/parser/parsers.h
Original file line number Diff line number Diff line change
Expand Up @@ -1005,6 +1005,13 @@ template<typename Ctx> MaybeResult<> foldedinstr(Ctx& ctx) {
auto inst = plaininstr(ctx, std::move(info.annotations));
assert(inst && "unexpectedly failed to parse instruction");
CHECK_ERR(inst);
// We have already parsed the instruction, so we generally know where it
// ends. But there may have been some invalid extra immediates (e.g.
// invalid memory indices) that we only realize are invalid now that we've
// parsed the instruction for real.
if (ctx.in.getPos() != *info.end) {
return ctx.in.err("expected end of instruction");
}
assert(ctx.in.getPos() == *info.end && "expected end of instruction");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can remove this assertion now.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops!

continue;
}
Expand Down
17 changes: 17 additions & 0 deletions test/lit/parse-bad-optional-memidx.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
;; Regression test for a parser bug where the invalid memory index followed by
;; another immediate caused an assertion failure.

;; RUN: not wasm-opt -all %s 2>&1 | filecheck %s

;; CHECK: Fatal: 12:22: error: expected end of instruction

(module
(memory 1 1)

(func $v128.load16_lane1 (param $0 i32) (param $1 v128) (result v128)
(v128.load16_lane 1 0 ;; invalid memory index
(local.get $0)
(local.get $1)
)
)
)