[PATCH] Fix PR66422

Richard Biener rguenther@suse.de
Mon Jun 8 10:47:00 GMT 2015


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,
+};



More information about the Gcc-patches mailing list