|
From: <sv...@va...> - 2015-06-22 11:53:57
|
Author: florian
Date: Mon Jun 22 12:53:48 2015
New Revision: 3155
Log:
Fix a few undefined shift operations as spotted by ubsan.
Modified:
trunk/priv/host_ppc_isel.c
trunk/priv/host_tilegx_isel.c
Modified: trunk/priv/host_ppc_isel.c
==============================================================================
--- trunk/priv/host_ppc_isel.c (original)
+++ trunk/priv/host_ppc_isel.c Mon Jun 22 12:53:48 2015
@@ -2475,19 +2475,21 @@
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 )
Modified: trunk/priv/host_tilegx_isel.c
==============================================================================
--- trunk/priv/host_tilegx_isel.c (original)
+++ trunk/priv/host_tilegx_isel.c Mon Jun 22 12:53:48 2015
@@ -369,12 +369,13 @@
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 )
|