@@ -147,6 +147,7 @@ class BinaryReaderInterp : public BinaryReaderNop {
147147 Result BeginFunctionBody (Index index, Offset size) override ;
148148 Result OnLocalDeclCount (Index count) override ;
149149 Result OnLocalDecl (Index decl_index, Index count, Type type) override ;
150+ Result EndLocalDecls () override ;
150151
151152 Result OnOpcode (Opcode Opcode) override ;
152153 Result OnAtomicLoadExpr (Opcode opcode,
@@ -849,17 +850,6 @@ Result BinaryReaderInterp::EndFunctionBody(Index index) {
849850Result BinaryReaderInterp::OnLocalDeclCount (Index count) {
850851 local_decl_count_ = count;
851852 local_count_ = 0 ;
852- // Continuation of the implicit func label, used for exception handling. (See
853- // BeginFunctionBody.)
854- // We need the local count for this, so we must do it here.
855- // NOTE: we don't count the parameters, as they're not part of the frame.
856- func_->handlers .push_back (HandlerDesc{HandlerKind::Catch,
857- istream_.end (),
858- Istream::kInvalidOffset ,
859- {},
860- {Istream::kInvalidOffset },
861- static_cast <u32 >(local_decl_count_),
862- 0 });
863853 return Result::Ok;
864854}
865855
@@ -870,10 +860,26 @@ Result BinaryReaderInterp::OnLocalDecl(Index decl_index,
870860
871861 local_count_ += count;
872862 func_->locals .push_back (LocalDesc{type, count, local_count_});
863+ return Result::Ok;
864+ }
873865
874- if (decl_index == local_decl_count_ - 1 ) {
866+ Result BinaryReaderInterp::EndLocalDecls () {
867+ if (local_count_ != 0 ) {
875868 istream_.Emit (Opcode::InterpAlloca, local_count_);
876869 }
870+ // Continuation of the implicit func label, used for exception handling. (See
871+ // BeginFunctionBody.)
872+ // We need the local count for this, which is only available after processing
873+ // all local decls.
874+ // NOTE: we don't count the parameters, as they're not part of the frame.
875+ func_->handlers .push_back (HandlerDesc{HandlerKind::Catch,
876+ istream_.end (),
877+ Istream::kInvalidOffset ,
878+ {},
879+ {Istream::kInvalidOffset },
880+ static_cast <u32 >(local_count_),
881+ 0 });
882+
877883 return Result::Ok;
878884}
879885
@@ -1522,7 +1528,7 @@ Result BinaryReaderInterp::OnTryExpr(Type sig_type) {
15221528 validator_.GetCatchCount (label_stack_.size () - 1 , &exn_stack_height));
15231529 // NOTE: *NOT* GetLocalCount. we don't count the parameters, as they're not
15241530 // part of the frame.
1525- u32 value_stack_height = validator_.type_stack_size () + local_decl_count_ ;
1531+ u32 value_stack_height = validator_.type_stack_size () + local_count_ ;
15261532 CHECK_RESULT (validator_.OnTry (GetLocation (), sig_type));
15271533 // Push a label that tracks mapping of exn -> catch
15281534 PushLabel (LabelKind::Try, Istream::kInvalidOffset , Istream::kInvalidOffset ,
0 commit comments