From: Richard Biener <rguenther@suse.de>
To: gcc-patches@gcc.gnu.org
Subject: [PATCH] Fix PR66422
Date: Mon, 08 Jun 2015 10:47:00 -0000 [thread overview]
Message-ID: <alpine.LSU.2.11.1506081243270.30088@zhemvz.fhfr.qr> (raw)
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,
+};
reply other threads:[~2015-06-08 10:44 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=alpine.LSU.2.11.1506081243270.30088@zhemvz.fhfr.qr \
--to=rguenther@suse.de \
--cc=gcc-patches@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).