Hi. Following patch prevents integer overflow with a huge param.
Patch can bootstrap on ppc64le-redhat-linux and survives regression tests. Ready to be installed? Martin
>From c92bbded326bb117d6c5bfcb1f505f2bbffc0b75 Mon Sep 17 00:00:00 2001 From: marxin <mli...@suse.cz> Date: Fri, 17 Feb 2017 13:46:21 +0100 Subject: [PATCH] Use HOST_WIDE_INT for a param calculation (PR rtl-optimization/79574). gcc/testsuite/ChangeLog: 2017-02-17 Martin Liska <mli...@suse.cz> PR rtl-optimization/79574 * gcc.dg/pr79574.c: New test. gcc/ChangeLog: 2017-02-17 Martin Liska <mli...@suse.cz> PR rtl-optimization/79574 * gcse.c (want_to_gcse_p): Prevent integer overflow. --- gcc/gcse.c | 5 +++-- gcc/testsuite/gcc.dg/pr79574.c | 11 +++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/pr79574.c diff --git a/gcc/gcse.c b/gcc/gcse.c index d28288df95c..5c6984c3240 100644 --- a/gcc/gcse.c +++ b/gcc/gcse.c @@ -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; diff --git a/gcc/testsuite/gcc.dg/pr79574.c b/gcc/testsuite/gcc.dg/pr79574.c new file mode 100644 index 00000000000..572f5230d5e --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr79574.c @@ -0,0 +1,11 @@ +/* PR rtl-optimization/79080 */ +/* { dg-do compile } */ +/* { dg-options "-Os --param gcse-cost-distance-ratio=2147483647" } */ + + +void a (void) +{ + volatile int b; + for (;; b) + ; +} -- 2.11.0