Merge pull request #18207 from unknownbrackets/irjit-safe-mem

irjit: Correct alignment checks against SP
This commit is contained in:
Henrik Rydgård 2023-09-23 23:25:12 +02:00 committed by GitHub
commit ae0305d974
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1794,7 +1794,8 @@ bool ApplyMemoryValidation(const IRWriter &in, IRWriter &out, const IROptions &o
bool spModified = false;
for (IRInst inst : in.GetInstructions()) {
IRMemoryOpInfo info = IROpMemoryAccessSize(inst.op);
if (info.size != 0 && inst.src1 == MIPS_REG_SP) {
// Note: we only combine word aligned accesses.
if (info.size != 0 && inst.src1 == MIPS_REG_SP && info.size == 4) {
if (spModified) {
// No good, it was modified and then we did more accesses. Can't combine.
spUpper = -1;
@ -1805,11 +1806,6 @@ bool ApplyMemoryValidation(const IRWriter &in, IRWriter &out, const IROptions &o
spUpper = -1;
break;
}
if (info.size == 16 && (inst.constant & 0xF) != 0) {
// Shouldn't happen, sp should always be aligned.
spUpper = -1;
break;
}
spLower = std::min(spLower, (int)inst.constant);
spUpper = std::max(spUpper, (int)inst.constant + info.size);
@ -1828,7 +1824,7 @@ bool ApplyMemoryValidation(const IRWriter &in, IRWriter &out, const IROptions &o
std::map<uint64_t, uint8_t> checks;
const auto addValidate = [&](IROp validate, uint8_t sz, const IRInst &inst, bool isStore) {
if (inst.src1 == MIPS_REG_SP && skipSP) {
if (inst.src1 == MIPS_REG_SP && skipSP && validate == IROp::ValidateAddress32) {
if (!flushedSP) {
out.Write(IROp::ValidateAddress32, 0, MIPS_REG_SP, spWrite ? 1U : 0U, spLower);
if (spUpper > spLower + 4)