This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[committed] PR82413: Mismatched precisions in build_range_check
- From: Richard Sandiford <richard dot sandiford at linaro dot org>
- To: gcc-patches at gcc dot gnu dot org
- Date: Wed, 04 Oct 2017 11:50:34 +0100
- Subject: [committed] PR82413: Mismatched precisions in build_range_check
- Authentication-results: sourceware.org; auth=none
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.
Tested on powerpc64le-linux-gnu and installed as obvious.
Richard
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.
Index: gcc/fold-const.c
===================================================================
--- gcc/fold-const.c 2017-10-04 11:43:11.653350269 +0100
+++ gcc/fold-const.c 2017-10-04 11:43:49.030813918 +0100
@@ -4851,7 +4851,7 @@ build_range_check (location_t loc, tree
{
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: gcc/testsuite/g++.dg/pr82413.C
===================================================================
--- /dev/null 2017-10-04 10:21:58.939451407 +0100
+++ gcc/testsuite/g++.dg/pr82413.C 2017-10-04 11:43:49.030813918 +0100
@@ -0,0 +1,3 @@
+bool a;
+int b;
+void c() { b &&a <= 0; }