From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 42339 invoked by alias); 17 Apr 2015 18:01:50 -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 42225 invoked by uid 89); 17 Apr 2015 18:01:49 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL,BAYES_00,SPF_PASS,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mailapp01.imgtec.com Received: from mailapp01.imgtec.com (HELO mailapp01.imgtec.com) (195.59.15.196) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 17 Apr 2015 18:01:48 +0000 Received: from KLMAIL01.kl.imgtec.org (unknown [192.168.5.35]) by Websense Email Security Gateway with ESMTPS id 33E4D3AED07B; Fri, 17 Apr 2015 19:01:42 +0100 (IST) Received: from BAMAIL02.ba.imgtec.org (10.20.40.28) by KLMAIL01.kl.imgtec.org (192.168.5.35) with Microsoft SMTP Server (TLS) id 14.3.195.1; Fri, 17 Apr 2015 19:01:45 +0100 Received: from [10.20.3.58] (10.20.3.58) by bamail02.ba.imgtec.org (10.20.40.28) with Microsoft SMTP Server (TLS) id 14.3.174.1; Fri, 17 Apr 2015 11:01:42 -0700 Message-ID: <1429293702.30498.239.camel@ubuntu-sellcey> Subject: Re: [PATCH] -Warray-bounds TLC From: Steve Ellcey Reply-To: To: Richard Biener CC: Date: Fri, 17 Apr 2015 18:01:00 -0000 In-Reply-To: References: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit MIME-Version: 1.0 X-SW-Source: 2015-04/txt/msg00919.txt.bz2 On Thu, 2015-04-16 at 13:55 +0200, Richard Biener wrote: > The following applies the patch produced earlier this year, applying > TLC to array bound warnings and catching a few more cases. > > Bootstrapped and tested on x86_64-unknown-linux-gnu, applied. > > Richard. > > 2015-04-16 Richard Biener > > PR tree-optimization/64277 > * tree-vrp.c (check_array_ref): Fix anti-range handling, > simplify upper bound handling. > (search_for_addr_array): Simplify. > (check_array_bounds): Handle ADDR_EXPRs here. > (check_all_array_refs): Simplify. This caused an interesting build failure of glibc when using the latest GCC. Here is a cut down case from elf/dl-open.c: extern void foo(void); struct s { int n; } v[1]; int bar (int i) { if ((i != 0 && i != -1 && i != -2) && (v[i].n == 0)) foo (); return 0; } int baz (int i) { if ((i != 0 && i != -2) && (v[i].n == 0)) foo (); return 0; } When compiled with -O2 -Wall -Werror, I now get an error about v[i] being out-of-bounds in bar. But I do not get this error in baz (where we don't check for -1. In reality, in glibc, we know that i can only be 0, -1, or -2. GCC of course doesn't know that. Does this error/warning seem right? The difference in behavior between bar and baz seems odd. Steve Ellcey sellcey@imgtec.com