re PR c/79731 (ICE: verify_gimple failed)
authorRichard Biener <rguenther@suse.de>
Tue, 28 Feb 2017 15:31:30 +0000 (15:31 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Tue, 28 Feb 2017 15:31:30 +0000 (15:31 +0000)
2017-02-28  Richard Biener  <rguenther@suse.de>

PR middle-end/79731
* fold-const.c (decode_field_reference): Reject out-of-bound
accesses.

* c-c++-common/torture/pr79731.c: New testcase.

From-SVN: r245779

gcc/ChangeLog
gcc/fold-const.c
gcc/testsuite/ChangeLog
gcc/testsuite/c-c++-common/torture/pr79731.c [new file with mode: 0644]

index 87478eec4314fb1045190e7ac2ba18c20ce45112..b65f820950f7bcbe28e62581a929a930f028a9e9 100644 (file)
@@ -1,3 +1,9 @@
+2017-02-28  Richard Biener  <rguenther@suse.de>
+
+       PR middle-end/79731
+       * fold-const.c (decode_field_reference): Reject out-of-bound
+       accesses.
+
 2017-02-28  Jakub Jelinek  <jakub@redhat.com>
 
        * config/i386/i386.c: Include intl.h.
index ad4770b43d2ae344930339bd65f09af592765329..3d63836068747f59338b8daa571f220013e44e0c 100644 (file)
@@ -4133,7 +4133,11 @@ decode_field_reference (location_t loc, tree *exp_, HOST_WIDE_INT *pbitsize,
                               punsignedp, preversep, pvolatilep);
   if ((inner == exp && and_mask == 0)
       || *pbitsize < 0 || offset != 0
-      || TREE_CODE (inner) == PLACEHOLDER_EXPR)
+      || TREE_CODE (inner) == PLACEHOLDER_EXPR
+      /* Reject out-of-bound accesses (PR79731).  */
+      || (! AGGREGATE_TYPE_P (TREE_TYPE (inner))
+         && compare_tree_int (TYPE_SIZE (TREE_TYPE (inner)),
+                              *pbitpos + *pbitsize) < 0))
     return 0;
 
   *exp_ = exp;
index b616b8a1738b052c431b960eaf96f15833a03bc7..82933d379f034fc513869ad2a677fef7b3c6e329 100644 (file)
@@ -1,3 +1,8 @@
+2017-02-28  Richard Biener  <rguenther@suse.de>
+
+       PR middle-end/79731
+       * c-c++-common/torture/pr79731.c: New testcase.
+
 2017-02-28  Richard Biener  <rguenther@suse.de>
 
        PR tree-optimization/79732
diff --git a/gcc/testsuite/c-c++-common/torture/pr79731.c b/gcc/testsuite/c-c++-common/torture/pr79731.c
new file mode 100644 (file)
index 0000000..cde2655
--- /dev/null
@@ -0,0 +1,18 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-Wno-psabi -w" } */
+
+typedef unsigned V __attribute__ ((vector_size (8)));
+V
+foo (unsigned x, V v)
+{
+  do {
+      v %= x;
+      x = 1;
+  } while (v[1]);
+  return v;
+}
+void fn2 ()
+{
+  V x = foo (5, (V) { 0, 1 });
+  if (x[0] || x[1] || x[2] || x[3]);
+}