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

This bug is reported by UBSan.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@216125 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Alexey Samsonov 2014-08-20 21:22:03 +00:00
parent a046b4149c
commit 145d28e73b
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);
}