From patchwork Fri Aug 30 15:13:07 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Meador Inge X-Patchwork-Id: 271327 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "www.sourceware.org", Issuer "StartCom Class 1 Primary Intermediate Server CA" (not verified)) by ozlabs.org (Postfix) with ESMTPS id A66572C008E for ; Sat, 31 Aug 2013 01:13:34 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id:mime-version:content-type; q=dns; s= default; b=ieqLmT+F/v/qVA6ETwFMw4W4L5+GZ3oylT66c5IBr0Ltd0lzdxgcA 5VRMBdBwEKnDU/j4fBFzqQ+32R4F92SKgqHZDGd7VW33Dpy8j42PDCQHTmV089Su EzA8xFmfj9nIU6BbLvbjImPprVtVHdialrkPdrBSqyW0zwPFbmnCG4= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id:mime-version:content-type; s= default; bh=p9NdDaHKgTmVYA06C4AsLfPWR+8=; b=rBSflMM5igXPENfISX8a jQ/tu01L+1cjzaHB46q+/3QUcObc7h/B7AwXRYAgiB+7c098hILCiJ1WPF290BfL HoMDlMt6ezpsysrYrLLSen/cDMiRCde/c3kasLqKjwBKHk+Dm2Q5J2iGVwlWNDsw k48d1dLY3YTR7N8wnCyhbvo= Received: (qmail 14666 invoked by alias); 30 Aug 2013 15:13:27 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 14654 invoked by uid 89); 30 Aug 2013 15:13:26 -0000 Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 30 Aug 2013 15:13:26 +0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.0 required=5.0 tests=AWL, BAYES_00, RDNS_NONE, SPF_HELO_FAIL autolearn=no version=3.3.2 X-HELO: relay1.mentorg.com Received: from svr-orw-fem-01.mgc.mentorg.com ([147.34.98.93]) by relay1.mentorg.com with esmtp id 1VFQO1-0005lg-SE from meador_inge@mentor.com for gcc-patches@gcc.gnu.org; Fri, 30 Aug 2013 08:13:21 -0700 Received: from SVR-ORW-FEM-02.mgc.mentorg.com ([147.34.96.206]) by svr-orw-fem-01.mgc.mentorg.com over TLS secured channel with Microsoft SMTPSVC(6.0.3790.4675); Fri, 30 Aug 2013 08:13:21 -0700 Received: from pepper.mgc.mentorg.com (147.34.91.1) by svr-orw-fem-02.mgc.mentorg.com (147.34.96.168) with Microsoft SMTP Server id 14.2.247.3; Fri, 30 Aug 2013 08:13:20 -0700 From: Meador Inge To: Subject: [PATCH] Don't issue array bound warnings on zero-length arrays Date: Fri, 30 Aug 2013 10:13:07 -0500 Message-ID: <1377875587-18004-1-git-send-email-meadori@codesourcery.com> MIME-Version: 1.0 Hi All, This patch fixes a minor issue that can occur when issuing array bounds warnings. In GNU C mode we allow empty lists and their upper bound is initialized to -1. This confuses the array bound analysis in VRP and in some cases we end up issuing false positives. This patch fixes the issue by bailing out when a zero-length array is encountered. OK for trunk? gcc/ 2013-08-30 Meador Inge * tree-vrp.c (check_array_ref): Bail out no emtpy arrays. gcc/testsuite/ 2013-08-30 Meador Inge * gcc.dg/Warray-bounds-11.c: New testcase. Index: gcc/testsuite/gcc.dg/Warray-bounds-11.c =================================================================== --- gcc/testsuite/gcc.dg/Warray-bounds-11.c (revision 0) +++ gcc/testsuite/gcc.dg/Warray-bounds-11.c (revision 0) @@ -0,0 +1,12 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -Warray-bounds -std=gnu99" } */ +/* Test zero-length arrays for GNU C. */ + +unsigned int a[] = { }; +unsigned int size_a; + +int test(void) +{ + /* This should not warn. */ + return size_a ? a[0] : 0; +} Index: gcc/tree-vrp.c =================================================================== --- gcc/tree-vrp.c (revision 202088) +++ gcc/tree-vrp.c (working copy) @@ -6137,9 +6137,10 @@ check_array_ref (location_t location, tr low_sub = up_sub = TREE_OPERAND (ref, 1); up_bound = array_ref_up_bound (ref); - /* Can not check flexible arrays. */ + /* Can not check flexible arrays or zero-length arrays. */ if (!up_bound - || TREE_CODE (up_bound) != INTEGER_CST) + || TREE_CODE (up_bound) != INTEGER_CST + || tree_int_cst_equal (up_bound, integer_minus_one_node)) return; /* Accesses to trailing arrays via pointers may access storage