Fix set iterators invalidation in find_parameters

This commit is contained in:
2025-06-04 09:19:10 +03:00
parent c6a0c73287
commit ae9cc2bf3b
2 changed files with 7 additions and 3 deletions

View File

@@ -131,9 +131,9 @@ static void lookup_for_vars(set<tuple<SgStatement*, string, MODE>>& where_to_add
if (worklist.count(result_arg)) if (worklist.count(result_arg))
{ {
worklist.erase(result_arg);
processArgument(worklist, arg1, cur_instr, first_instr); processArgument(worklist, arg1, cur_instr, first_instr);
processArgument(worklist, arg2, cur_instr, first_instr); processArgument(worklist, arg2, cur_instr, first_instr);
worklist.erase(result_arg);
} }
if (instr->getOperation() == SAPFOR::CFG_OP::PARAM && worklist.count(arg1)) if (instr->getOperation() == SAPFOR::CFG_OP::PARAM && worklist.count(arg1))
@@ -159,6 +159,8 @@ static void lookup_for_vars(set<tuple<SgStatement*, string, MODE>>& where_to_add
const auto& RD = bblock->getRD_In(); const auto& RD = bblock->getRD_In();
map<SAPFOR::BasicBlock*, SAPFOR::Instruction*> group_by_block; map<SAPFOR::BasicBlock*, SAPFOR::Instruction*> group_by_block;
set<SAPFOR::Argument*> to_erase;
for (auto& arg : worklist) for (auto& arg : worklist)
{ {
if (RD.count(arg)) if (RD.count(arg))
@@ -175,7 +177,7 @@ static void lookup_for_vars(set<tuple<SgStatement*, string, MODE>>& where_to_add
__spf_print(1, "Please specify value of variable %s on line %d of file %s\n", arg->getValue().c_str(), line, filename); __spf_print(1, "Please specify value of variable %s on line %d of file %s\n", arg->getValue().c_str(), line, filename);
auto toAdd = make_tuple(stmt_after, var_name, MODE::BEFORE); auto toAdd = make_tuple(stmt_after, var_name, MODE::BEFORE);
where_to_add.insert(toAdd); where_to_add.insert(toAdd);
worklist.erase(arg); to_erase.insert(arg);
} }
else else
{ {
@@ -186,6 +188,8 @@ static void lookup_for_vars(set<tuple<SgStatement*, string, MODE>>& where_to_add
} }
} }
} }
for (const auto& arg : to_erase)
worklist.erase(arg);
while (bblock && group_by_block.find(bblock) == group_by_block.end()) while (bblock && group_by_block.find(bblock) == group_by_block.end())
bblock = bblock->getDom(); bblock = bblock->getDom();

View File

@@ -5,7 +5,7 @@
#include <set> #include <set>
#include <vector> #include <vector>
#include "..\GraphCall\graph_calls.h" #include "../GraphCall/graph_calls.h"
using ResultSet = std::set<std::tuple<std::string, int, std::string>>; using ResultSet = std::set<std::tuple<std::string, int, std::string>>;