Merge pull request #9675 from JosJuice/jit64-div-80000000

Jit64: Fix UB/infinite loop when compiling division by 0x80000000
This commit is contained in:
Léo Lam 2021-04-26 23:50:27 +02:00 committed by GitHub
commit 51bf2dca21
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 3 deletions

View File

@ -1480,9 +1480,9 @@ void Jit64::divwx(UGeckoInstruction inst)
if (inst.OE)
GenerateConstantOverflow(false);
}
else if (MathUtil::IsPow2(divisor) || MathUtil::IsPow2(-divisor))
else if (MathUtil::IsPow2(divisor) || MathUtil::IsPow2(-static_cast<s64>(divisor)))
{
u32 abs_val = std::abs(divisor);
const u32 abs_val = static_cast<u32>(std::abs(static_cast<s64>(divisor)));
X64Reg tmp = RSCRATCH;
if (Ra.IsSimpleReg() && Ra.GetSimpleReg() != Rd)

View File

@ -16,7 +16,7 @@ struct Magic
// Calculate the constants required to optimize a signed 32-bit integer division.
// Taken from The PowerPC Compiler Writer's Guide and LLVM.
// Divisor must not be -1, 0, and 1.
// Divisor must not be -1, 0, 1 or INT_MIN.
Magic SignedDivisionConstants(s32 divisor);
} // namespace JitCommon