Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
21 changes: 13 additions & 8 deletions src/interp/binary-reader-interp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -831,13 +831,6 @@ Result BinaryReaderInterp::BeginFunctionBody(Index index, Offset size) {
// try-delegate instruction.
PushLabel(LabelKind::Try, Istream::kInvalidOffset, Istream::kInvalidOffset,
func_->handlers.size());
func_->handlers.push_back(HandlerDesc{HandlerKind::Catch,
istream_.end(),
Istream::kInvalidOffset,
{},
{Istream::kInvalidOffset},
static_cast<u32>(func_->locals.size()),
0});
return Result::Ok;
}

Expand All @@ -856,6 +849,16 @@ Result BinaryReaderInterp::EndFunctionBody(Index index) {
Result BinaryReaderInterp::OnLocalDeclCount(Index count) {
local_decl_count_ = count;
local_count_ = 0;
// FIXME(Soni): does the value of `values` even matter here? it used to be
// always 0 when this call was in BeginFunctionBody.
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure this FIXME comment is useful, maybe just remove it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yeah that's fair.

... ugh, the more we look at all this code the more questionable stuff we find, like the func_->handlers.size() in BeginFunctionBody (which, presumably, always evaluates to 0?). but that's not the fix we came here for.

// NOTE: we don't count the parameters, as they're not part of the frame.
func_->handlers.push_back(HandlerDesc{HandlerKind::Catch,
istream_.end(),
Istream::kInvalidOffset,
{},
{Istream::kInvalidOffset},
static_cast<u32>(local_decl_count_),
Copy link
Member

Choose a reason for hiding this comment

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

The previous code uses func_->locals.size() here. How is that different? Perhaps you could mention in the PR description how the old code is wrong?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

0});
return Result::Ok;
}

Expand Down Expand Up @@ -1516,7 +1519,9 @@ Result BinaryReaderInterp::OnTryExpr(Type sig_type) {
u32 exn_stack_height;
CHECK_RESULT(
validator_.GetCatchCount(label_stack_.size() - 1, &exn_stack_height));
u32 value_stack_height = validator_.type_stack_size();
// NOTE: *NOT* GetLocalCount. we don't count the parameters, as they're not
// part of the frame.
u32 value_stack_height = validator_.type_stack_size() + local_decl_count_;
CHECK_RESULT(validator_.OnTry(GetLocation(), sig_type));
// Push a label that tracks mapping of exn -> catch
PushLabel(LabelKind::Try, Istream::kInvalidOffset, Istream::kInvalidOffset,
Expand Down
22 changes: 22 additions & 0 deletions test/regress/interp-ehv3-locals.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
;;; TOOL: run-interp-spec
;;; ARGS*: --enable-exceptions
;;; NOTE: ref: issue-2476
(module
(tag $e0)
(func (export "broken-local") (result i32)
(local $value i32)
(try $try
(do
(local.set $value (i32.const 1))
(throw $e0)
)
(catch $e0)
)
(local.get $value)
)
)

(assert_return (invoke "broken-local") (i32.const 1))
(;; STDOUT ;;;
2/2 tests passed.
;;; STDOUT ;;)