re PR middle-end/80100 (simplify-rtx.c sanitizer detects undefined behaviour with...
authorJakub Jelinek <jakub@redhat.com>
Tue, 11 Apr 2017 17:21:51 +0000 (19:21 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Tue, 11 Apr 2017 17:21:51 +0000 (19:21 +0200)
PR middle-end/80100
* simplify-rtx.c (simplify_binary_operation_1) <case IOR>: Perform
left shift in unsigned HOST_WIDE_INT type.

* gcc.dg/pr80100.c: New test.

From-SVN: r246851

gcc/ChangeLog
gcc/simplify-rtx.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr80100.c [new file with mode: 0644]

index ea434f6e280ae2f78363ae45244829fbb8ea1e50..e5b4c75f380d77aafac63bb9c4ef2e8c6db7c815 100644 (file)
@@ -1,5 +1,9 @@
 2017-04-11  Jakub Jelinek  <jakub@redhat.com>
 
+       PR middle-end/80100
+       * simplify-rtx.c (simplify_binary_operation_1) <case IOR>: 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.
index 4bbbe2354e3f21f2bfa98987d97ad64b4a27032b..ce632aeabb89c804799290d4ba79d8cd985cd634 100644 (file)
@@ -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
index a01828881749eb66caed763734dbcdc1cdccaf44..d8597e2b59709473106c963ae8dbfdc969d754c0 100644 (file)
@@ -1,5 +1,8 @@
 2017-04-11  Jakub Jelinek  <jakub@redhat.com>
 
+       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 (file)
index 0000000..0d462be
--- /dev/null
@@ -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));
+}