Fix undefined behavior (left shift of negative value) in Hexagon backend.

This bug is reported by UBSan.

llvm-svn: 216125
This commit is contained in:
Alexey Samsonov 2014-08-20 21:22:03 +00:00
parent ea0aee622e
commit 2651ae6513
2 changed files with 6 additions and 6 deletions

View File

@ -1766,7 +1766,7 @@ int HexagonInstrInfo::getMinValue(const MachineInstr *MI) const {
& HexagonII::ExtentBitsMask;
if (isSigned) // if value is signed
return -1 << (bits - 1);
return -1U << (bits - 1);
else
return 0;
}
@ -1780,9 +1780,9 @@ int HexagonInstrInfo::getMaxValue(const MachineInstr *MI) const {
& HexagonII::ExtentBitsMask;
if (isSigned) // if value is signed
return ~(-1 << (bits - 1));
return ~(-1U << (bits - 1));
else
return ~(-1 << bits);
return ~(-1U << bits);
}
// Returns true if an instruction can be converted into a non-extended

View File

@ -155,7 +155,7 @@ int HexagonMCInst::getMinValue(void) const {
& HexagonII::ExtentBitsMask;
if (isSigned) // if value is signed
return -1 << (bits - 1);
return -1U << (bits - 1);
else
return 0;
}
@ -170,7 +170,7 @@ int HexagonMCInst::getMaxValue(void) const {
& HexagonII::ExtentBitsMask;
if (isSigned) // if value is signed
return ~(-1 << (bits - 1));
return ~(-1U << (bits - 1));
else
return ~(-1 << bits);
return ~(-1U << bits);
}