[decompiler] fix bad cast and crash on bad and/or recognition (#626)

* fix small bugs

* fix missing inlining of derefs
This commit is contained in:
water111
2021-06-25 20:13:22 -04:00
committed by GitHub
parent bfc1173ed5
commit 409be41596
7 changed files with 30 additions and 19 deletions
+2
View File
@@ -1798,6 +1798,7 @@ DerefElement::DerefElement(Form* base, bool is_addr_of, DerefToken token)
x.expr()->parent_element = this;
}
}
inline_nested();
}
DerefElement::DerefElement(Form* base, bool is_addr_of, std::vector<DerefToken> tokens)
@@ -1808,6 +1809,7 @@ DerefElement::DerefElement(Form* base, bool is_addr_of, std::vector<DerefToken>
x.expr()->parent_element = this;
}
}
inline_nested();
}
goos::Object DerefElement::to_form_internal(const Env& env) const {
+4 -2
View File
@@ -3382,10 +3382,12 @@ void ArrayFieldAccess::update_with_val(Form* new_val,
if (m_expected_stride == 1) {
// reg0 is idx
auto reg0_matcher =
Matcher::match_or({Matcher::cast("int", Matcher::any(0)), Matcher::any(0)});
Matcher::match_or({Matcher::cast("int", Matcher::any(0)),
Matcher::cast("uint", Matcher::any(0)), Matcher::any(0)});
// reg1 is base
auto reg1_matcher =
Matcher::match_or({Matcher::cast("int", Matcher::any(1)), Matcher::any(1)});
Matcher::match_or({Matcher::cast("int", Matcher::any(1)),
Matcher::cast("uint", Matcher::any(1)), Matcher::any(1)});
auto matcher = Matcher::fixed_op(FixedOperatorKind::ADDITION, {reg0_matcher, reg1_matcher});
auto match_result = match(matcher, new_val);
if (!match_result.matched) {
+2 -2
View File
@@ -854,8 +854,8 @@ std::string ObjectFileDB::ir2_function_to_string(ObjectFileData& data, Function&
auto& op = func.get_atomic_op_at_instr(instr_id);
op_id = func.ir2.atomic_ops->instruction_to_atomic_op.at(instr_id);
append_commented(line, printed_comment,
op.to_form(data.linked_data.labels, func.ir2.env).print() + "[" +
std::to_string(op_id) + "]");
fmt::format("[{:3d}] {}", op_id,
op.to_form(data.linked_data.labels, func.ir2.env).print()));
if (func.ir2.env.has_type_analysis()) {
append_commented(
+7
View File
@@ -537,6 +537,13 @@ bool try_splitting_nested_sc(FormPool& pool, Function& func, ShortCircuitElement
assert(ir->entries.front().branch_delay.has_value());
bool first_is_and = delay_slot_sets_false(first_branch.first, *ir->entries.front().branch_delay);
bool first_is_or = delay_slot_sets_truthy(first_branch.first, *ir->entries.front().branch_delay);
if (first_is_and == first_is_or) {
throw std::runtime_error(fmt::format(
"Failed to split nested sc. This may mean that abs/ash/type-of was misrecognized as "
"and/or:\n{}",
ir->to_string(func.ir2.env)));
}
assert(first_is_and != first_is_or); // one or the other but not both!
int first_different = -1; // the index of the first one that's different.