aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJeff Law <law@redhat.com>2015-10-23 13:16:53 -0600
committerJeff Law <law@gcc.gnu.org>2015-10-23 13:16:53 -0600
commit0a8c1e23903c43a5869abef9bff30337f6122137 (patch)
treede244e9c75eefeef6b1158112ed8ee8c63e19a8f /gcc
parent7e8efecbaf4fb902b5b092655640591d7531e4f7 (diff)
downloadgcc-0a8c1e23903c43a5869abef9bff30337f6122137.zip
gcc-0a8c1e23903c43a5869abef9bff30337f6122137.tar.gz
gcc-0a8c1e23903c43a5869abef9bff30337f6122137.tar.bz2
[RFA] Fix pr67830, another type narrowing problem
PR tree-optimization/67830 * match.pd ((bit_and (plus/minus (convert @0) (convert @1)) mask)): Explicitly verify the mask has no bits outside the type of the innermost operands. PR tree-optimization/67830 * gcc.dg/pr67830.c: New test. From-SVN: r229267
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog7
-rw-r--r--gcc/match.pd4
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/gcc.dg/pr67830.c22
4 files changed, 36 insertions, 2 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 5aef5b7..29d1ffa 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,10 @@
+2015-10-23 Jeff Law <law@redhat.com>
+
+ PR tree-optimization/67830
+ * match.pd ((bit_and (plus/minus (convert @0) (convert @1)) mask)):
+ Explicitly verify the mask has no bits outside the type of
+ the innermost operands.
+
2015-10-23 Gregor Richards <gregor.richards@uwaterloo.ca>
Szabolcs Nagy <szabolcs.nagy@arm.com>
diff --git a/gcc/match.pd b/gcc/match.pd
index d182f68..d6ab94e 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -2719,8 +2719,8 @@ along with GCC; see the file COPYING3. If not see
&& types_match (@0, @1)
&& (tree_int_cst_min_precision (@4, TYPE_SIGN (TREE_TYPE (@0)))
<= TYPE_PRECISION (TREE_TYPE (@0)))
- && (TYPE_OVERFLOW_WRAPS (TREE_TYPE (@0))
- || tree_int_cst_sgn (@4) >= 0))
+ && (wi::bit_and (@4, wi::mask (TYPE_PRECISION (TREE_TYPE (@0)),
+ true, TYPE_PRECISION (type))) == 0))
(if (TYPE_OVERFLOW_WRAPS (TREE_TYPE (@0)))
(with { tree ntype = TREE_TYPE (@0); }
(convert (bit_and (op @0 @1) (convert:ntype @4))))
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index bedb76a..fed7d10 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2015-10-23 Jeff Law <law@redhat.com>
+
+ PR tree-optimization/67830
+ * gcc.dg/pr67830.c: New test.
+
2015-10-23 Jan Hubicka <hubicka@ucw.cz>
* gcc.dg/tree-ssa/operand-equal-2.c: New testcase.
diff --git a/gcc/testsuite/gcc.dg/pr67830.c b/gcc/testsuite/gcc.dg/pr67830.c
new file mode 100644
index 0000000..9bfb0c0
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr67830.c
@@ -0,0 +1,22 @@
+/* PR tree-optimization/67830 */
+/* { dg-do run } */
+/* { dg-options "-O2" } */
+
+int a, b, *g, h;
+unsigned char c, d;
+
+int
+main ()
+{
+ int f, e = -2;
+ b = e;
+ g = &b;
+ h = c = a + 1;
+ f = d - h;
+ *g &= f;
+
+ if (b != -2)
+ __builtin_abort ();
+
+ return 0;
+}