[decompiler] fix missing casts issue (#573)

* fix casts issue

* fix bug

* one last small fix
This commit is contained in:
water111
2021-06-09 21:35:13 -04:00
committed by GitHub
parent 12d72c7897
commit 92afd62e2c
102 changed files with 340 additions and 528 deletions
+43 -2
View File
@@ -590,18 +590,56 @@ void update_var_info(VariableNames::VarInfo* info,
const TypeState& ts,
int var_id,
const DecompilerTypeSystem& dts) {
auto& type = ts.get(reg);
if (info->initialized) {
assert(info->reg_id.id == var_id);
assert(info->reg_id.reg == reg);
bool changed;
info->type = dts.tp_lca(info->type, ts.get(reg), &changed);
info->type = dts.tp_lca(info->type, type, &changed);
} else {
info->reg_id.id = var_id;
info->reg_id.reg = reg;
info->type = ts.get(reg);
info->type = type;
info->initialized = true;
}
}
bool merge_infos(VariableNames::VarInfo* info1,
VariableNames::VarInfo* info2,
const DecompilerTypeSystem& dts) {
if (info1->initialized && info2->initialized) {
bool changed;
auto new_type = dts.tp_lca(info1->type, info2->type, &changed);
if (changed) {
// fmt::print("changed new to {} from {} {} ({} {})\n", new_type.print(),
// info1->type.print(),
// info2->type.print(), info1->reg_id.print(), info2->reg_id.print());
info1->type = new_type;
info2->type = new_type;
return true;
}
}
return false;
}
void merge_infos(
std::unordered_map<Register, std::vector<VariableNames::VarInfo>, Register::hash>& info1,
std::unordered_map<Register, std::vector<VariableNames::VarInfo>, Register::hash>& info2,
const DecompilerTypeSystem& dts) {
for (auto& [reg, infos] : info1) {
auto other = info2.find(reg);
if (other != info2.end()) {
for (size_t i = 0; i < std::min(other->second.size(), infos.size()); i++) {
merge_infos(&infos.at(i), &other->second.at(i), dts);
}
}
}
}
} // namespace
/*!
@@ -613,6 +651,7 @@ void SSA::make_vars(const Function& function, const DecompilerTypeSystem& dts) {
const TypeState* init_types = &function.ir2.env.get_types_at_block_entry(block_id);
for (auto& instr : block.ins) {
auto op_id = instr.op_id;
const TypeState* end_types = &function.ir2.env.get_types_after_op(op_id);
if (instr.dst.has_value()) {
@@ -645,6 +684,8 @@ void SSA::make_vars(const Function& function, const DecompilerTypeSystem& dts) {
}
}
merge_infos(program_write_vars, program_read_vars, dts);
// copy types from input argument coloring moves:
for (auto& instr : blocks.at(0).ins) {
if (instr.is_arg_coloring_move) {