From 82e3eff9742c92e13aef25035b40488f5339618d Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Tue, 10 Jan 2023 10:46:02 -0800 Subject: Fix iterator invalidation bug in GlobalStructInference (#5414) Fixes #5406 --- src/passes/GlobalStructInference.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src') 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); -- cgit v1.2.3