TypeDeterminer: Fix type map iterations

`DetermineStorageTextureSubtype()` may add types to the module while these types are being iterated over, leading to UB.

To work around, collect all the storage texture types into a vector first, and iterate over these.

Change-Id: Ib94b1df52d6ccbbf635a6d89eeeabef46ba03416
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/37261
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
Ben Clayton 2021-01-11 21:14:22 +00:00 committed by Commit Bot service account
parent d221738e20
commit 4527a512eb
1 changed files with 12 additions and 9 deletions

View File

@ -89,15 +89,18 @@ void TypeDeterminer::set_referenced_from_function_if_needed(ast::Variable* var,
}
bool TypeDeterminer::Determine() {
for (auto& iter : mod_->types()) {
auto& type = iter.second;
if (auto* storage = type->As<ast::type::StorageTexture>()) {
if (!DetermineStorageTextureSubtype(storage)) {
set_error(Source{},
"unable to determine storage texture subtype for: " +
type->type_name());
return false;
}
std::vector<ast::type::StorageTexture*> storage_textures;
for (auto& it : mod_->types()) {
if (auto* storage = it.second->As<ast::type::StorageTexture>()) {
storage_textures.emplace_back(storage);
}
}
for (auto* storage : storage_textures) {
if (!DetermineStorageTextureSubtype(storage)) {
set_error(Source{}, "unable to determine storage texture subtype for: " +
storage->type_name());
return false;
}
}