Skip to content

Commit 7fdccf7

Browse files
authored
wasm-interp: Fix off-by-one in DoThrow (#2486)
1 parent b15a13e commit 7fdccf7

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/interp/interp.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2615,7 +2615,8 @@ RunResult Thread::DoThrow(Exception::Ptr exn) {
26152615
auto iter = handlers.rbegin();
26162616
while (iter != handlers.rend()) {
26172617
const HandlerDesc& handler = *iter;
2618-
if (pc >= handler.try_start_offset && pc < handler.try_end_offset) {
2618+
// pc points to the *next* instruction by the time we're in DoThrow.
2619+
if (pc > handler.try_start_offset && pc <= handler.try_end_offset) {
26192620
// For a try-delegate, skip part of the traversal by directly going
26202621
// up to an outer handler specified by the delegate depth.
26212622
if (handler.kind == HandlerKind::Delegate) {
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
;;; TOOL: run-interp-spec
2+
;;; ARGS*: --enable-exceptions
3+
(module
4+
(tag $e0)
5+
(func (export "throws")
6+
(throw $e0)
7+
(try $try
8+
(do
9+
)
10+
(catch $e0)
11+
)
12+
)
13+
)
14+
15+
(assert_exception (invoke "throws"))
16+
(;; STDOUT ;;;
17+
out/test/regress/interp-throw-before-try.txt:15: assert_exception passed
18+
2/2 tests passed.
19+
;;; STDOUT ;;)

0 commit comments

Comments
 (0)