PR tree-optimization/86741 - ICE in -Warray-bounds indexing into an object of incompl...
authorMartin Sebor <msebor@redhat.com>
Tue, 31 Jul 2018 16:47:39 +0000 (16:47 +0000)
committerMartin Sebor <msebor@gcc.gnu.org>
Tue, 31 Jul 2018 16:47:39 +0000 (10:47 -0600)
gcc/ChangeLog:

PR tree-optimization/86741
* tree-vrp.c (vrp_prop::check_mem_ref): Avoid incomplete types.

gcc/testsuite/ChangeLog:

PR tree-optimization/86741
* gcc.dg/Warray-bounds-33.c: New test.

From-SVN: r263166

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/Warray-bounds-33.c [new file with mode: 0644]
gcc/tree-vrp.c

index 50bd14c7af1d888e8c914e9f70b250097374575a..bcaa74cfbd6462d6c1ccbb93c2344209fb43d04e 100644 (file)
@@ -1,3 +1,8 @@
+2018-07-31  Martin Sebor  <msebor@redhat.com>
+
+       PR tree-optimization/86741
+       * tree-vrp.c (vrp_prop::check_mem_ref): Avoid incomplete types.
+
 2018-07-31  Andreas Krebbel  <krebbel@linux.ibm.com>
 
        * config/s390/s390.c (s390_expand_setmem): Make the unrolling to
index f741d280fd5d08905a3673367451ba964a6901f6..a6a13b3cba9c68c21f8e9542c5aacd05bee5a75b 100644 (file)
@@ -1,3 +1,8 @@
+2018-07-31  Martin Sebor  <msebor@redhat.com>
+
+       PR tree-optimization/86741
+       * gcc.dg/Warray-bounds-33.c: New test.
+
 2018-07-31  Andreas Krebbel  <krebbel@linux.ibm.com>
 
        * gcc.target/s390/memset-1.c: Improve testcase.
diff --git a/gcc/testsuite/gcc.dg/Warray-bounds-33.c b/gcc/testsuite/gcc.dg/Warray-bounds-33.c
new file mode 100644 (file)
index 0000000..28f14b4
--- /dev/null
@@ -0,0 +1,36 @@
+/* PR tree-optimization/86741 - ICE in -Warray-bounds indexing into
+   an object of incomplete type
+   { dg-do compile }
+   { dg-options "-O2 -Wall" }  */
+
+struct S
+{
+  int s;
+};
+
+void f (void);
+
+void test_void (void)
+{
+  extern void v;
+  struct S *b = (struct S*)&v;
+  if (b->s)
+    f ();
+}
+
+void test_incomplete_enum (void)
+{
+  extern enum E e;
+  struct S *b = (struct S*)&e;
+  if (b->s)
+    f ();
+}
+
+void test_func (void)
+{
+  struct S *b = (struct S*)&f;
+  if (b->s)
+    f ();
+}
+
+/* { dg-prune-output "taking address of expression of type .void." } */
index 7ab8898b4534a1ef003a8d0ff1e98c6752deadd3..1944ae4f4db6b76c78035843b97f8757f8249082 100644 (file)
@@ -5048,9 +5048,12 @@ vrp_prop::check_mem_ref (location_t location, tree ref, bool ignore_off_by_one)
      a reference/subscript via a pointer to an object that is not
      an element of an array.  References to members of structs and
      unions are excluded because MEM_REF doesn't make it possible
-     to identify the member where the reference originated.  */
+     to identify the member where the reference originated.
+     Incomplete types are excluded as well because their size is
+     not known.  */
   tree reftype = TREE_TYPE (arg);
   if (POINTER_TYPE_P (reftype)
+      || !COMPLETE_TYPE_P (reftype)
       || RECORD_OR_UNION_TYPE_P (reftype))
     return;