PR82413: Mismatched precisions in build_range_check
authorRichard Sandiford <richard.sandiford@linaro.org>
Wed, 4 Oct 2017 10:50:19 +0000 (10:50 +0000)
committerRichard Sandiford <rsandifo@gcc.gnu.org>
Wed, 4 Oct 2017 10:50:19 +0000 (10:50 +0000)
build_range_check explicitly allows LOW and HIGH to be a different type
from EXP, so we need to use w::to_widest when comparing a value based on
HIGH with a value based on EXP's type.

2017-10-04  Richard Sandiford  <richard.sandiford@linaro.org>

gcc/
PR tree-optimization/82413
* fold-const.c (build_range_check): Use widest_int when comparing
the maximum ETYPE value with HIGH.

gcc/testsuite/
PR tree-optimization/82413
* g++.dg/pr82413.C: New test.

From-SVN: r253401

gcc/ChangeLog
gcc/fold-const.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/pr82413.C [new file with mode: 0644]

index a4fd9d8336516ca7eed645460680dbf4ae7c20b6..76c1f1b403ec912122269a6378d824f2d677452b 100644 (file)
@@ -1,3 +1,9 @@
+2017-10-04  Richard Sandiford  <richard.sandiford@linaro.org>
+
+       PR tree-optimization/82413
+       * fold-const.c (build_range_check): Use widest_int when comparing
+       the maximum ETYPE value with HIGH.
+
 2017-10-04  Wilco Dijkstra  <wdijkstr@arm.com>
 
        PR rtl-optimization/82396
index fa9d1bb20ff503231f77eb85ccbd548594d14c3f..ae037ce14fbfd2c01bc474b6770186d90f3bec39 100644 (file)
@@ -4851,7 +4851,7 @@ build_range_check (location_t loc, tree type, tree exp, int in_p,
     {
       int prec = TYPE_PRECISION (etype);
 
-      if (wi::mask (prec - 1, false, prec) == high)
+      if (wi::mask <widest_int> (prec - 1, false) == wi::to_widest (high))
        {
          if (TYPE_UNSIGNED (etype))
            {
index 883392f796cc6b8000854186197cd71b89fb9b8a..2c96f3af4e6ffa157904c80f254366baa6fe0379 100644 (file)
@@ -1,3 +1,8 @@
+2017-10-04  Richard Sandiford  <richard.sandiford@linaro.org>
+
+       PR tree-optimization/82413
+       * g++.dg/pr82413.C: New test.
+
 2017-10-04  Paul Thomas  <pault@gcc.gnu.org>
 
        PR fortran/77296
diff --git a/gcc/testsuite/g++.dg/pr82413.C b/gcc/testsuite/g++.dg/pr82413.C
new file mode 100644 (file)
index 0000000..a44751d
--- /dev/null
@@ -0,0 +1,3 @@
+bool a;
+int b;
+void c() { b &&a <= 0; }