]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Fix a few undefined shift operations as spotted by ubsan.
authorFlorian Krohm <florian@eich-krohm.de>
Mon, 22 Jun 2015 11:53:48 +0000 (11:53 +0000)
committerFlorian Krohm <florian@eich-krohm.de>
Mon, 22 Jun 2015 11:53:48 +0000 (11:53 +0000)
git-svn-id: svn://svn.valgrind.org/vex/trunk@3155

VEX/priv/host_ppc_isel.c
VEX/priv/host_tilegx_isel.c

index 40fe8951e0b45ce47ada54fc27632cc4720c756a..aae7754f3400b498991194353e258c7d4abaa999 100644 (file)
@@ -2475,19 +2475,21 @@ static HReg iselWordExpr_R_wrk ( ISelEnv* env, IRExpr* e,
 static Bool uInt_fits_in_16_bits ( UInt u ) 
 {
    /* Is u the same as the sign-extend of its lower 16 bits? */
-   Int i = u & 0xFFFF;
-   i <<= 16;
-   i >>= 16;
-   return toBool(u == (UInt)i);
+   UInt v = u & 0xFFFF;
+
+   v = (Int)(v << 16) >> 16;   /* sign extend */
+
+   return u == v;
 }
 
 static Bool uLong_fits_in_16_bits ( ULong u ) 
 {
    /* Is u the same as the sign-extend of its lower 16 bits? */
-   Long i = u & 0xFFFFULL;
-   i <<= 48;
-   i >>= 48;
-   return toBool(u == (ULong)i);
+   ULong v = u & 0xFFFFULL;
+
+   v = (Long)(v << 48) >> 48;   /* sign extend */
+
+   return u == v;
 }
 
 static Bool uLong_is_4_aligned ( ULong u )
index 7e4e6eb45f10810fa8fc4e788f5aa9aed44c16cf..47c7da68b1b576f943be424946256552bc6e86e2 100644 (file)
@@ -369,12 +369,13 @@ static void doHelperCall ( ISelEnv * env, IRExpr * guard, IRCallee * cee,
    result.  The expression may only be a word-size one.
 */
 
-static Bool uInt_fits_in_16_bits ( UInt u )
+static Bool uInt_fits_in_16_bits ( UInt u ) 
 {
-  Int i = u & 0xFFFF;
-  i <<= 16;
-  i >>= 16;
-  return toBool(u == (UInt) i);
+   UInt v = u & 0xFFFF;
+
+   v = (Int)(v << 16) >> 16;   /* sign extend */
+
+   return u == v;
 }
 
 static Bool sane_AMode ( ISelEnv * env, TILEGXAMode * am )