summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2023-01-10 10:46:02 -0800
committerGitHub <noreply@github.com>2023-01-10 10:46:02 -0800
commit82e3eff9742c92e13aef25035b40488f5339618d (patch)
tree986336b1258d6d1035430e2531fd0f58467b97e1
parenta803a0830586aaa3e9c989403881298b430f312c (diff)
downloadbinaryen-82e3eff9742c92e13aef25035b40488f5339618d.tar.gz
binaryen-82e3eff9742c92e13aef25035b40488f5339618d.tar.bz2
binaryen-82e3eff9742c92e13aef25035b40488f5339618d.zip
Fix iterator invalidation bug in GlobalStructInference (#5414)
Fixes #5406
-rw-r--r--src/passes/GlobalStructInference.cpp4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/passes/GlobalStructInference.cpp b/src/passes/GlobalStructInference.cpp
index 901a51a9f..89ab155f8 100644
--- a/src/passes/GlobalStructInference.cpp
+++ b/src/passes/GlobalStructInference.cpp
@@ -157,7 +157,9 @@ struct GlobalStructInference : public Pass {
// unoptimizable type makes all its supertypes unoptimizable as well.
// TODO: this could be specific per field (and not all supers have all
// fields)
- for (auto type : unoptimizable) {
+ // Iterate on a copy to avoid invalidation as we insert.
+ auto unoptimizableCopy = unoptimizable;
+ for (auto type : unoptimizableCopy) {
while (1) {
unoptimizable.insert(type);