[vm/bytecode] Fix iteration of bytecode local variables

Previously, BytecodeLocalVariablesIterator::IsDone() returned true
when iterator was standing at the last entry.
As a result, if the last entry is a scope without variables, then it was
ignored and bytecode flow graph builder would not get a correct context
level for that scope.

The fix is for IsDone() to return true only after stepping past the last
entry.

Fixes service/async_generator_breakpoint_test/1 with bytecode.

Change-Id: I768eec9a0e43342cc0f155a6c35cb3de50f3d14a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/116880
Reviewed-by: Régis Crelier <regis@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
This commit is contained in:
Alexander Markov 2019-09-11 23:46:29 +00:00 committed by commit-bot@chromium.org
parent eac977bef0
commit 586869c3f6

View file

@ -436,10 +436,11 @@ class BytecodeLocalVariablesIterator : ValueObject {
}
bool MoveNext() {
if (entries_remaining_ == 0) {
if (entries_remaining_ <= 0) {
// Finished looking at the last entry, now we're done.
entries_remaining_ = -1;
return false;
}
ASSERT(entries_remaining_ > 0);
--entries_remaining_;
cur_kind_and_flags_ = reader_.ReadByte();
cur_start_pc_ += reader_.ReadSLEB128();
@ -464,7 +465,10 @@ class BytecodeLocalVariablesIterator : ValueObject {
return true;
}
bool IsDone() const { return entries_remaining_ == 0; }
// Returns true after iterator moved past the last entry and
// MoveNext() returned false.
bool IsDone() const { return entries_remaining_ < 0; }
intptr_t Kind() const { return cur_kind_and_flags_ & kKindMask; }
bool IsScope() const { return Kind() == kScope; }
bool IsVariableDeclaration() const { return Kind() == kVariableDeclaration; }