Fix small bug traversing users in interface_var_sroa (#4850)
Fix code that is traversing def-use user structure at the same time
that it is changing it. This is dicey at best and error prone at worst.
This was uncovered making a change to the id_to_user representation.
diff --git a/source/opt/interface_var_sroa.cpp b/source/opt/interface_var_sroa.cpp
index 58ed897..1b2cb36 100644
--- a/source/opt/interface_var_sroa.cpp
+++ b/source/opt/interface_var_sroa.cpp
@@ -212,8 +212,12 @@
context()->KillInst(inst);
return;
}
+ std::vector<Instruction*> users;
context()->get_def_use_mgr()->ForEachUser(
- inst, [this](Instruction* user) { KillInstructionAndUsers(user); });
+ inst, [&users](Instruction* user) { users.push_back(user); });
+ for (auto user : users) {
+ context()->KillInst(user);
+ }
context()->KillInst(inst);
}