From f95810b50bab4e1397e51b12aa8e73cbf6046a47 Mon Sep 17 00:00:00 2001 From: Richard Sandiford Date: Wed, 4 Oct 2017 10:50:19 +0000 Subject: [PATCH] PR82413: Mismatched precisions in build_range_check 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 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 | 6 ++++++ gcc/fold-const.c | 2 +- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/pr82413.C | 3 +++ 4 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/pr82413.C diff --git a/gcc/ChangeLog b/gcc/ChangeLog index a4fd9d8..76c1f1b 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2017-10-04 Richard Sandiford + + 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 PR rtl-optimization/82396 diff --git a/gcc/fold-const.c b/gcc/fold-const.c index fa9d1bb..ae037ce 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -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 (prec - 1, false) == wi::to_widest (high)) { if (TYPE_UNSIGNED (etype)) { diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 883392f..2c96f3a 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2017-10-04 Richard Sandiford + + PR tree-optimization/82413 + * g++.dg/pr82413.C: New test. + 2017-10-04 Paul Thomas PR fortran/77296 diff --git a/gcc/testsuite/g++.dg/pr82413.C b/gcc/testsuite/g++.dg/pr82413.C new file mode 100644 index 0000000..a44751d --- /dev/null +++ b/gcc/testsuite/g++.dg/pr82413.C @@ -0,0 +1,3 @@ +bool a; +int b; +void c() { b &&a <= 0; } -- 2.7.4