From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 38064 invoked by alias); 8 Jun 2015 10:44:47 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 38055 invoked by uid 89); 8 Jun 2015 10:44:46 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.2 required=5.0 tests=AWL,BAYES_00,KAM_ASCII_DIVIDERS,KAM_LAZY_DOMAIN_SECURITY,T_RP_MATCHES_RCVD autolearn=no version=3.3.2 X-HELO: mx2.suse.de Received: from cantor2.suse.de (HELO mx2.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (CAMELLIA256-SHA encrypted) ESMTPS; Mon, 08 Jun 2015 10:44:45 +0000 Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id D3E2AAAC7 for ; Mon, 8 Jun 2015 10:44:42 +0000 (UTC) Date: Mon, 08 Jun 2015 10:47:00 -0000 From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix PR66422 Message-ID: User-Agent: Alpine 2.11 (LSU 23 2013-08-11) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-SW-Source: 2015-06/txt/msg00550.txt.bz2 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 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, +};