From 9b918e82027599898e5f2ff75342a51da06672a9 Mon Sep 17 00:00:00 2001 From: Aldy Hernandez Date: Wed, 3 Oct 2018 17:36:29 +0000 Subject: [PATCH] re PR tree-optimization/87415 (wrong code at -O1 and above on x86_64-linux-gnu) PR tree-optimization/87415 * tree-vrp.c (set_value_range_with_overflow): Special case one bit precision fields. From-SVN: r264817 --- gcc/ChangeLog | 6 ++++++ gcc/testsuite/gcc.dg/pr87415.c | 20 ++++++++++++++++++++ gcc/tree-vrp.c | 9 +++++++++ 3 files changed, 35 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/pr87415.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index aa10aa07269..30d7e775c61 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2018-10-03 Aldy Hernandez + + PR tree-optimization/87415 + * tree-vrp.c (set_value_range_with_overflow): Special case one bit + precision fields. + 2018-10-02 Jeff Law * gimple-fold.c (get_range_strlen): Only set *nonstr when diff --git a/gcc/testsuite/gcc.dg/pr87415.c b/gcc/testsuite/gcc.dg/pr87415.c new file mode 100644 index 00000000000..473384ac479 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr87415.c @@ -0,0 +1,20 @@ +/* { dg-do run } */ +/* { dg-options "-O2" } */ + +struct A +{ + int b:1; +}; + +int d; + +int main () +{ + struct A e = { 0 }; + if (!d) + e.b = -1; + if (!e.b) + __builtin_abort (); + + return 0; +} diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c index 005fc2ffe2d..cbc2ea2f26b 100644 --- a/gcc/tree-vrp.c +++ b/gcc/tree-vrp.c @@ -1116,6 +1116,15 @@ set_value_range_with_overflow (value_range &vr, const unsigned int prec = TYPE_PRECISION (type); vr.type = VR_RANGE; vr.equiv = NULL; + + /* For one bit precision if max < min, then the swapped + range covers all values. */ + if (prec == 1 && wi::lt_p (wmax, wmin, sgn)) + { + set_value_range_to_varying (&vr); + return; + } + if (TYPE_OVERFLOW_WRAPS (type)) { /* If overflow wraps, truncate the values and adjust the -- 2.30.2