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>
diff --git a/src/type_determiner.cc b/src/type_determiner.cc
index 72551bd..0dc61d4 100644
--- a/src/type_determiner.cc
+++ b/src/type_determiner.cc
@@ -89,15 +89,18 @@
}
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;
}
}