Fix undefined behavior (left shift of negative value) in Hexagon backend.
authorAlexey Samsonov <vonosmas@gmail.com>
Wed, 20 Aug 2014 21:22:03 +0000 (21:22 +0000)
committerAlexey Samsonov <vonosmas@gmail.com>
Wed, 20 Aug 2014 21:22:03 +0000 (21:22 +0000)
This bug is reported by UBSan.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@216125 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/Hexagon/HexagonInstrInfo.cpp
lib/Target/Hexagon/MCTargetDesc/HexagonMCInst.cpp

index 41de8489ed826fc8bbef2d3aed61f616aec13183..a63e3826f071180e31c07deb880fb48ea5c4aa07 100644 (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
index 98b8db0763820509c33cef72871f08985b84d7b4..c842b9b7cf3d5e70179f188075f476c2207156c2 100644 (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);
 }