fix decompiler crash (#294)

This commit is contained in:
water111 2021-02-28 19:22:53 -05:00 committed by GitHub
parent 9d3b056b7a
commit b0686b1ea7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 15 deletions

View file

@ -114,9 +114,17 @@ class Env {
}
const UseDefInfo& get_use_def_info(const RegisterAccess& ra) const;
void disable_use(const RegisterAccess& access) { m_var_names.disable_use(access); }
void disable_use(const RegisterAccess& access) {
if (has_local_vars()) {
m_var_names.disable_use(access);
}
}
void disable_def(const RegisterAccess& access) { m_var_names.disable_def(access); }
void disable_def(const RegisterAccess& access) {
if (has_local_vars()) {
m_var_names.disable_def(access);
}
}
LinkedObjectFile* file = nullptr;
DecompilerTypeSystem* dts = nullptr;

View file

@ -453,22 +453,24 @@ bool try_clean_up_sc_as_or(FormPool& pool, Function& func, ShortCircuitElement*
// we also want to fix up the use/def info for the result.
// it's somewhat arbitrary, but we use the convention that the short-circuit defs
// are eliminated:
auto& ud_info = func.ir2.env.get_use_def_info(as_set->dst());
if (i == int(ir->entries.size()) - 2) {
if (ud_info.def_count() == 1) {
// the final case of the or doesn't explicitly set the destination register.
// this can happen if the move is eliminated during coloring.
// for now, let's leave this last def here, just so it looks like _something_ sets it.
// TODO - what if this isn't a def in the last slot? Does it matter?
if (func.ir2.env.has_local_vars()) {
auto& ud_info = func.ir2.env.get_use_def_info(as_set->dst());
if (i == int(ir->entries.size()) - 2) {
if (ud_info.def_count() == 1) {
// the final case of the or doesn't explicitly set the destination register.
// this can happen if the move is eliminated during coloring.
// for now, let's leave this last def here, just so it looks like _something_ sets it.
// TODO - what if this isn't a def in the last slot? Does it matter?
} else {
// lg::warn("Disabling def of {} in final or delay slot",
// as_set->to_string(func.ir2.env));
func.ir2.env.disable_def(as_set->dst());
}
} else {
// lg::warn("Disabling def of {} in final or delay slot",
// as_set->to_string(func.ir2.env));
// lg::warn("Disabling def of {} in or delay slot", as_set->to_string(func.ir2.env));
func.ir2.env.disable_def(as_set->dst());
}
} else {
// lg::warn("Disabling def of {} in or delay slot", as_set->to_string(func.ir2.env));
func.ir2.env.disable_def(as_set->dst());
}
if (i == 0) {