From 0cadbfaa89805ce4d1b93bed04c10d7c7bf1f6e2 Mon Sep 17 00:00:00 2001 From: Marc Glisse Date: Sat, 24 Aug 2013 00:16:08 +0200 Subject: re PR other/57324 (Undefined behavior issues found with clang's -fsanitize=undefined) 2013-08-24 Marc Glisse PR other/57324 * hwint.h (HOST_WIDE_INT_UC, HOST_WIDE_INT_1U, HOST_WIDE_INT_M1, HOST_WIDE_INT_M1U): New macros. * fold-const.c (sign_bit_p, build_range_check, fold_unary_loc, fold_binary_loc, fold_ternary_loc): Use the new macros. Use an unsigned -1 for lshift. * cse.c (cse_insn): Likewise. * double-int.c (rshift_double, lshift_double): Likewise. * builtins.c (fold_builtin_bitop): Likewise. * combine.c (force_to_mode): Likewise. * tree.c (integer_pow2p, tree_log2, tree_floor_log2): Likewise. * simplify-rtx.c (simplify_const_unary_operation, simplify_const_binary_operation): Likewise. * tree-stdarg.c (va_list_counter_bump, va_list_ptr_read, check_va_list_escapes): Likewise. * rtlanal.c (nonzero_bits1): Likewise. * expmed.c (expand_smod_pow2): Likewise. * tree-ssa-structalias.c (UNKNOWN_OFFSET): Use HOST_WIDE_INT_MIN. From-SVN: r201953 --- gcc/simplify-rtx.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'gcc/simplify-rtx.c') diff --git a/gcc/simplify-rtx.c b/gcc/simplify-rtx.c index 17a3d12..65a5906 100644 --- a/gcc/simplify-rtx.c +++ b/gcc/simplify-rtx.c @@ -2018,14 +2018,13 @@ simplify_const_unary_operation (enum rtx_code code, enum machine_mode mode, /* Test against the signed lower bound. */ if (width > HOST_BITS_PER_WIDE_INT) { - th = (unsigned HOST_WIDE_INT) (-1) - << (width - HOST_BITS_PER_WIDE_INT - 1); + th = HOST_WIDE_INT_M1U << (width - HOST_BITS_PER_WIDE_INT - 1); tl = 0; } else { th = -1; - tl = (unsigned HOST_WIDE_INT) (-1) << (width - 1); + tl = HOST_WIDE_INT_M1U << (width - 1); } real_from_integer (&t, VOIDmode, tl, th, 0); if (REAL_VALUES_LESS (x, t)) @@ -4191,7 +4190,7 @@ simplify_const_binary_operation (enum rtx_code code, enum machine_mode mode, /* Sign-extend the result for arithmetic right shifts. */ if (code == ASHIFTRT && arg0s < 0 && arg1 > 0) - val |= ((unsigned HOST_WIDE_INT) (-1)) << (width - arg1); + val |= HOST_WIDE_INT_M1U << (width - arg1); break; case ROTATERT: -- cgit v1.1