Skip to content

Commit

Permalink
Reject binary ops where the source is an uninitialized register
Browse files Browse the repository at this point in the history
Signed-off-by: Alan Jowett <[email protected]>
  • Loading branch information
Alan Jowett committed Oct 18, 2024
1 parent 9f25cee commit 06b7fff
Show file tree
Hide file tree
Showing 3 changed files with 507 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/assertions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,15 +193,10 @@ class AssertExtractor {

vector<Assert> operator()(const Atomic& ins) const {
vector<Assert> res;
res.emplace_back(TypeConstraint{ins.valreg, TypeGroup::number});
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;
}

Expand Down Expand Up @@ -246,7 +241,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 06b7fff

Please sign in to comment.