public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Fix PR66422
@ 2015-06-08 10:47 Richard Biener
  0 siblings, 0 replies; only message in thread
From: Richard Biener @ 2015-06-08 10:47 UTC (permalink / raw)
  To: gcc-patches


The following patch should fix the bogus array-bound warning caused
by loop peeling which fails to split blocks after inserted unreachable
calls (which is now "fatal" to optimization after removing the
quadraticness in CFG cleanup to scan for noreturn calls).

Bootstrap and regtest in progress on x86_64-unknown-linux-gnu.

Richard.

2015-06-08  Richard Biener  <rguenther@suse.de>

	PR tree-optimization/66422
	* tree-ssa-loop-ivcanon.c (remove_exits_and_undefined_stmts): Split
	block after inserted gcc_unreachable.

	* gcc.dg/Warray-bounds-16.c: New testcase.

Index: gcc/tree-ssa-loop-ivcanon.c
===================================================================
--- gcc/tree-ssa-loop-ivcanon.c	(revision 224212)
+++ gcc/tree-ssa-loop-ivcanon.c	(working copy)
@@ -520,9 +520,9 @@ remove_exits_and_undefined_stmts (struct
 	  gimple_stmt_iterator gsi = gsi_for_stmt (elt->stmt);
 	  gcall *stmt = gimple_build_call
 	      (builtin_decl_implicit (BUILT_IN_UNREACHABLE), 0);
-
 	  gimple_set_location (stmt, gimple_location (elt->stmt));
 	  gsi_insert_before (&gsi, stmt, GSI_NEW_STMT);
+	  split_block (gimple_bb (stmt), stmt);
 	  changed = true;
 	  if (dump_file && (dump_flags & TDF_DETAILS))
 	    {
Index: gcc/testsuite/gcc.dg/Warray-bounds-16.c
===================================================================
--- gcc/testsuite/gcc.dg/Warray-bounds-16.c	(revision 0)
+++ gcc/testsuite/gcc.dg/Warray-bounds-16.c	(working copy)
@@ -0,0 +1,40 @@
+/* { dg-do compile } */
+/* { dg-options "-O3 -Warray-bounds" } */
+
+typedef struct foo {
+    unsigned char foo_size;
+    int buf[4];
+    const char* bar;
+} foo;
+
+const foo *get_foo(int index);
+
+static int foo_loop(const foo *myfoo) {
+    int i;
+    if (myfoo->foo_size < 3)
+        return 0;
+    for (i = 0; i < myfoo->foo_size; i++) {
+        if (myfoo->buf[i] != 1) /* { dg-bogus "above array bounds" } */
+            return 0;
+    }
+
+    return 1;
+}
+
+static int run_foo(void) {
+    int i;
+    for (i = 0; i < 1; i++) {
+        const foo *myfoo = get_foo(i);
+        if (foo_loop(myfoo))
+            return 0;
+    }
+    return -1;
+}
+
+typedef struct hack {
+    int (*func)(void);
+} hack;
+
+hack myhack = {
+    .func = run_foo,
+};

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2015-06-08 10:44 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-08 10:47 [PATCH] Fix PR66422 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).