From df1c878ec25af7e9405b0276e6478fd996c2d3f9 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Tue, 11 Apr 2017 19:21:51 +0200 Subject: [PATCH] re PR middle-end/80100 (simplify-rtx.c sanitizer detects undefined behaviour with optimization) PR middle-end/80100 * simplify-rtx.c (simplify_binary_operation_1) : Perform left shift in unsigned HOST_WIDE_INT type. * gcc.dg/pr80100.c: New test. From-SVN: r246851 --- gcc/ChangeLog | 4 ++++ gcc/simplify-rtx.c | 4 ++-- gcc/testsuite/ChangeLog | 3 +++ gcc/testsuite/gcc.dg/pr80100.c | 9 +++++++++ 4 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/pr80100.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index ea434f6e280..e5b4c75f380 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,5 +1,9 @@ 2017-04-11 Jakub Jelinek + PR middle-end/80100 + * simplify-rtx.c (simplify_binary_operation_1) : Perform + left shift in unsigned HOST_WIDE_INT type. + PR rtl-optimization/80385 * simplify-rtx.c (simplify_unary_operation_1): Don't transform (not (neg X)) into (plus X -1) for complex or non-integral modes. diff --git a/gcc/simplify-rtx.c b/gcc/simplify-rtx.c index 4bbbe2354e3..ce632aeabb8 100644 --- a/gcc/simplify-rtx.c +++ b/gcc/simplify-rtx.c @@ -2741,8 +2741,8 @@ simplify_binary_operation_1 (enum rtx_code code, machine_mode mode, && CONST_INT_P (XEXP (op0, 1)) && INTVAL (XEXP (op0, 1)) < HOST_BITS_PER_WIDE_INT) { - int count = INTVAL (XEXP (op0, 1)); - HOST_WIDE_INT mask = INTVAL (trueop1) << count; + int count = INTVAL (XEXP (op0, 1)); + HOST_WIDE_INT mask = UINTVAL (trueop1) << count; if (mask >> count == INTVAL (trueop1) && trunc_int_for_mode (mask, mode) == mask diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index a0182888174..d8597e2b597 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,8 @@ 2017-04-11 Jakub Jelinek + PR middle-end/80100 + * gcc.dg/pr80100.c: New test. + PR rtl-optimization/80385 * g++.dg/opt/pr80385.C: New test. diff --git a/gcc/testsuite/gcc.dg/pr80100.c b/gcc/testsuite/gcc.dg/pr80100.c new file mode 100644 index 00000000000..0d462be30aa --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr80100.c @@ -0,0 +1,9 @@ +/* PR middle-end/80100 */ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ + +long int +foo (long int x) +{ + return 2L | ((x - 1L) >> (__SIZEOF_LONG__ * __CHAR_BIT__ - 1)); +} -- 2.30.2