Fix infinite loop

Fix the infinite loop caused by 6e459fecb7.
That commit changed the behaviour of a sem::Statement::Block method for
sem::BlockStatement instances. Now, the method returns the block itself
instead of the outer block which causes an infinite loop when iterating
over a chain of blocks.

Change-Id: I0eab3f7f166dbe38477bbefd222edb9cf0da53b5
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/61060
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Vasyl Teliman <vasniktel@gmail.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
This commit is contained in:
Vasyl Teliman 2021-08-07 17:33:20 +00:00 committed by Tint LUCI CQ
parent b2619443d9
commit 32e905f4cb
1 changed files with 3 additions and 1 deletions

View File

@ -19,6 +19,7 @@
#include "src/ast/module.h"
#include "src/ast/variable_decl_statement.h"
#include "src/castable.h"
#include "src/program.h"
#include "src/sem/block_statement.h"
#include "src/sem/statement.h"
@ -51,7 +52,8 @@ std::vector<const sem::Variable*> GetAllVarsInScope(
std::vector<const sem::Variable*> result;
// Walk up the hierarchy of blocks in which `curr_stmt` is contained.
for (const auto* block = curr_stmt->Block(); block; block = block->Block()) {
for (const auto* block = curr_stmt->Block(); block;
block = tint::As<sem::BlockStatement>(block->Parent())) {
for (const auto* stmt : *block->Declaration()) {
if (stmt == curr_stmt->Declaration()) {
// `curr_stmt` was found. This is only possible if `block is the