public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] avoid incomplete types in -Warray-bounds (PR 86741)
@ 2018-07-30 20:16 Martin Sebor
  2018-07-31  9:50 ` Richard Biener
  0 siblings, 1 reply; 2+ messages in thread
From: Martin Sebor @ 2018-07-30 20:16 UTC (permalink / raw)
  To: Gcc Patch List

[-- Attachment #1: Type: text/plain, Size: 335 bytes --]

The enhanced handling of MEM_REFs in -Warray-bounds assumes
the object from whose address an offset is being computed has
a complete type.  Since the size of such objects isn't known,
whether the offset (or index) from its beginning is valid
cannot be reliably determined.  The attached patch avoids
dealing with such objects.

Martin

[-- Attachment #2: gcc-86741.diff --]
[-- Type: text/x-patch, Size: 1953 bytes --]

PR tree-optimization/86741 - ICE in -Warray-bounds indexing into an object of incomplete type

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.

Index: gcc/testsuite/gcc.dg/Warray-bounds-33.c
===================================================================
--- gcc/testsuite/gcc.dg/Warray-bounds-33.c	(nonexistent)
+++ gcc/testsuite/gcc.dg/Warray-bounds-33.c	(working copy)
@@ -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: gcc/tree-vrp.c
===================================================================
--- gcc/tree-vrp.c	(revision 263072)
+++ gcc/tree-vrp.c	(working copy)
@@ -5048,9 +5048,12 @@ vrp_prop::check_mem_ref (location_t location, tree
      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;
 

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] avoid incomplete types in -Warray-bounds (PR 86741)
  2018-07-30 20:16 [PATCH] avoid incomplete types in -Warray-bounds (PR 86741) Martin Sebor
@ 2018-07-31  9:50 ` Richard Biener
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2018-07-31  9:50 UTC (permalink / raw)
  To: Martin Sebor; +Cc: GCC Patches

On Mon, Jul 30, 2018 at 10:16 PM Martin Sebor <msebor@gmail.com> wrote:
>
> The enhanced handling of MEM_REFs in -Warray-bounds assumes
> the object from whose address an offset is being computed has
> a complete type.  Since the size of such objects isn't known,
> whether the offset (or index) from its beginning is valid
> cannot be reliably determined.  The attached patch avoids
> dealing with such objects.

Looks ok to deal with the testcase, thus please install.

Richard.




> Martin

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-07-31  9:50 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-30 20:16 [PATCH] avoid incomplete types in -Warray-bounds (PR 86741) Martin Sebor
2018-07-31  9:50 ` Richard Biener

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).