Use HOST_WIDE_INT for a param calculation (PR rtl-optimization/79574).
authorMartin Liska <mliska@suse.cz>
Fri, 17 Feb 2017 14:46:14 +0000 (15:46 +0100)
committerMartin Liska <marxin@gcc.gnu.org>
Fri, 17 Feb 2017 14:46:14 +0000 (14:46 +0000)
2017-02-17  Martin Liska  <mliska@suse.cz>

PR rtl-optimization/79574
* gcc.dg/pr79574.c: New test.
2017-02-17  Martin Liska  <mliska@suse.cz>

PR rtl-optimization/79574
* gcse.c (want_to_gcse_p): Prevent integer overflow.

From-SVN: r245531

gcc/ChangeLog
gcc/gcse.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr79574.c [new file with mode: 0644]

index defd5431ef15cd20c2d9442b0de9efd602000b2a..ec8049b68179fb79acf256adbfb36b9f99a99a17 100644 (file)
@@ -1,3 +1,8 @@
+2017-02-17  Martin Liska  <mliska@suse.cz>
+
+       PR rtl-optimization/79574
+       * gcse.c (want_to_gcse_p): Prevent integer overflow.
+
 2017-02-17  Martin Liska  <mliska@suse.cz>
 
        PR tree-optimization/79529
index d28288df95c076ffeb5327d9609593536fb19b53..5c6984c3240b25af00548114a1bafbf7e412792d 100644 (file)
@@ -790,7 +790,7 @@ want_to_gcse_p (rtx x, machine_mode mode, int *max_distance_ptr)
        /* PRE doesn't implement max_distance restriction.  */
        {
          int cost;
-         int max_distance;
+         HOST_WIDE_INT max_distance;
 
          gcc_assert (!optimize_function_for_speed_p (cfun)
                      && optimize_function_for_size_p (cfun));
@@ -798,7 +798,8 @@ want_to_gcse_p (rtx x, machine_mode mode, int *max_distance_ptr)
 
          if (cost < COSTS_N_INSNS (GCSE_UNRESTRICTED_COST))
            {
-             max_distance = (GCSE_COST_DISTANCE_RATIO * cost) / 10;
+             max_distance
+               = ((HOST_WIDE_INT)GCSE_COST_DISTANCE_RATIO * cost) / 10;
              if (max_distance == 0)
                return 0;
 
index abd9308a80a761a857a5d1f606baa84d2e00d3c9..d0a95d48af425bbaafcc088e38d40f55fa0f6789 100644 (file)
@@ -1,3 +1,8 @@
+2017-02-17  Martin Liska  <mliska@suse.cz>
+
+       PR rtl-optimization/79574
+       * gcc.dg/pr79574.c: New test.
+
 2017-02-17  Marek Polacek  <polacek@redhat.com>
 
        PR middle-end/79536
diff --git a/gcc/testsuite/gcc.dg/pr79574.c b/gcc/testsuite/gcc.dg/pr79574.c
new file mode 100644 (file)
index 0000000..1b666e2
--- /dev/null
@@ -0,0 +1,10 @@
+/* PR rtl-optimization/79574 */
+/* { dg-do compile } */
+/* { dg-options "-Os --param gcse-cost-distance-ratio=2147483647" } */
+
+void a (void)
+{
+  volatile int b;
+  for (;; b)
+    ;
+}