Fix for ZAM inlining of nested function calls with the same parameter names

This commit is contained in:
Vern Paxson 2024-05-15 17:32:13 -07:00
parent ca62898a11
commit 9e5977f24e
3 changed files with 53 additions and 29 deletions

View file

@ -359,11 +359,27 @@ NameExprPtr Reducer::GenInlineBlockName(const IDPtr& id) {
return make_intrusive<NameExpr>(GenLocal(id));
}
NameExprPtr Reducer::PushInlineBlock(TypePtr type) {
void Reducer::PushInlineBlock() {
++inline_block_level;
block_locals.emplace_back(std::unordered_map<const ID*, IDPtr>());
}
void Reducer::PopInlineBlock() {
--inline_block_level;
for ( auto& l : block_locals.back() ) {
auto key = l.first;
auto prev = l.second;
if ( prev )
orig_to_new_locals[key] = prev;
else
orig_to_new_locals.erase(key);
}
block_locals.pop_back();
}
NameExprPtr Reducer::GetRetVar(TypePtr type) {
if ( ! type || type->Tag() == TYPE_VOID )
return nullptr;
@ -382,21 +398,6 @@ NameExprPtr Reducer::PushInlineBlock(TypePtr type) {
return GenInlineBlockName(ret_id);
}
void Reducer::PopInlineBlock() {
--inline_block_level;
for ( auto& l : block_locals.back() ) {
auto key = l.first;
auto prev = l.second;
if ( prev )
orig_to_new_locals[key] = prev;
else
orig_to_new_locals.erase(key);
}
block_locals.pop_back();
}
ExprPtr Reducer::NewVarUsage(IDPtr var, const Expr* orig) {
auto var_usage = make_intrusive<NameExpr>(var);
BindExprToCurrStmt(var_usage);