mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-28 06:32:09 +00:00
Fix undefined behavior (left shift of negative value) in SystemZ backend.
This bug is reported by UBSan. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@216131 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
dac67649f2
commit
d1e3fcf347
@ -294,7 +294,7 @@ static void emitIncrement(MachineBasicBlock &MBB,
|
|||||||
else {
|
else {
|
||||||
Opcode = SystemZ::AGFI;
|
Opcode = SystemZ::AGFI;
|
||||||
// Make sure we maintain 8-byte stack alignment.
|
// Make sure we maintain 8-byte stack alignment.
|
||||||
int64_t MinVal = -int64_t(1) << 31;
|
int64_t MinVal = -uint64_t(1) << 31;
|
||||||
int64_t MaxVal = (int64_t(1) << 31) - 8;
|
int64_t MaxVal = (int64_t(1) << 31) - 8;
|
||||||
if (ThisVal < MinVal)
|
if (ThisVal < MinVal)
|
||||||
ThisVal = MinVal;
|
ThisVal = MinVal;
|
||||||
|
@ -2800,14 +2800,10 @@ SystemZTargetLowering::emitAtomicLoadBinary(MachineInstr *MI,
|
|||||||
unsigned Tmp = MRI.createVirtualRegister(RC);
|
unsigned Tmp = MRI.createVirtualRegister(RC);
|
||||||
BuildMI(MBB, DL, TII->get(BinOpcode), Tmp)
|
BuildMI(MBB, DL, TII->get(BinOpcode), Tmp)
|
||||||
.addReg(RotatedOldVal).addOperand(Src2);
|
.addReg(RotatedOldVal).addOperand(Src2);
|
||||||
if (BitSize < 32)
|
if (BitSize <= 32)
|
||||||
// XILF with the upper BitSize bits set.
|
// XILF with the upper BitSize bits set.
|
||||||
BuildMI(MBB, DL, TII->get(SystemZ::XILF), RotatedNewVal)
|
BuildMI(MBB, DL, TII->get(SystemZ::XILF), RotatedNewVal)
|
||||||
.addReg(Tmp).addImm(uint32_t(~0 << (32 - BitSize)));
|
.addReg(Tmp).addImm(-1U << (32 - BitSize));
|
||||||
else if (BitSize == 32)
|
|
||||||
// XILF with every bit set.
|
|
||||||
BuildMI(MBB, DL, TII->get(SystemZ::XILF), RotatedNewVal)
|
|
||||||
.addReg(Tmp).addImm(~uint32_t(0));
|
|
||||||
else {
|
else {
|
||||||
// Use LCGR and add -1 to the result, which is more compact than
|
// Use LCGR and add -1 to the result, which is more compact than
|
||||||
// an XILF, XILH pair.
|
// an XILF, XILH pair.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user