Skip to content

Commit

Permalink
Reject binary ops where the source is an uninitialized register (#740)
Browse files Browse the repository at this point in the history
Signed-off-by: Alan Jowett <[email protected]>
  • Loading branch information
Alan-Jowett authored Oct 19, 2024
1 parent 9f25cee commit 9d0df3b
Show file tree
Hide file tree
Showing 3 changed files with 513 additions and 12 deletions.
27 changes: 15 additions & 12 deletions src/assertions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,17 +192,13 @@ class AssertExtractor {
}

vector<Assert> operator()(const Atomic& ins) const {
vector<Assert> res;
res.emplace_back(TypeConstraint{ins.access.basereg, TypeGroup::pointer});
res.emplace_back(
ValidAccess{ins.access.basereg, ins.access.offset, Imm{static_cast<uint32_t>(ins.access.width)}, false});
if (ins.op == Atomic::Op::CMPXCHG) {
// The memory contents pointed to by ins.access will be compared
// against the value of the ins.valreg register. Only numbers are
// supported.
res.emplace_back(TypeConstraint{ins.valreg, TypeGroup::number});
}
return res;

return {
Assert{TypeConstraint{ins.valreg, TypeGroup::number}},
Assert{TypeConstraint{ins.access.basereg, TypeGroup::pointer}},
Assert{ValidAccess{ins.access.basereg, ins.access.offset, Imm{static_cast<uint32_t>(ins.access.width)},
false}},
};
}

vector<Assert> operator()(const Un ins) const { return {Assert{TypeConstraint{ins.dst, TypeGroup::number}}}; }
Expand Down Expand Up @@ -246,7 +242,14 @@ class AssertExtractor {
}
return {Assert{TypeConstraint{ins.dst, TypeGroup::number}}};
}
default: return {Assert{TypeConstraint{ins.dst, TypeGroup::number}}};
// For all other binary operations, the destination register must be a number and the source must either be an immediate or a number.
default:
if (const auto src = std::get_if<Reg>(&ins.v)) {
return {Assert{TypeConstraint{ins.dst, TypeGroup::number}},
Assert{TypeConstraint{*src, TypeGroup::number}}};
} else {
return {Assert{TypeConstraint{ins.dst, TypeGroup::number}}};
}
}
assert(false);
}
Expand Down
1 change: 1 addition & 0 deletions src/test/test_yaml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,6 @@ YAML_CASE("test-data/sext.yaml")
YAML_CASE("test-data/shift.yaml")
YAML_CASE("test-data/stack.yaml")
YAML_CASE("test-data/subtract.yaml")
YAML_CASE("test-data/uninit.yaml")
YAML_CASE("test-data/unop.yaml")
YAML_CASE("test-data/unsigned.yaml")
Loading

0 comments on commit 9d0df3b

Please sign in to comment.