From patchwork Fri Dec 8 14:44:03 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 846284 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-468792-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="eOPZVV6w"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3ytZqj5bT5z9s82 for ; Sat, 9 Dec 2017 01:44:17 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=D3VEhETdtm5BoHJdibLhcUjyD0Z7Eo4pbFGt0EXBzBIEjM4wMVJnT 1vwxhfnQ30aHPyG7Kz79jYlTIEYH8vphRAGT8KpEPb9JoF12QdS3/SnzYVWU93Ih qmqGQBEPBrCHlNcSgoARXHQexNvsnn8QNS5ismMbGRcIWSqde6TnqY= 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:date :from:to:subject:message-id:mime-version:content-type; s= default; bh=Joa5plhbjYDKrI2x6xflNgTy3uI=; b=eOPZVV6wZ5lqDoY9IFlY bGd7CUXB8QOqFiLt0QjOM/dthJUA+UTU0xaRvAOM6u+HnfV81zDt+d5sdhsT+Rib glVm7Tyv1XLnXXvS6T5+D7YBZk84Hi3Aoch7YMvWPhj2hnN+93CRQRkWKK0P3YfJ TPcAWshV3DrW9toTHy1cy0Q= Received: (qmail 114623 invoked by alias); 8 Dec 2017 14:44:07 -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 114548 invoked by uid 89); 8 Dec 2017 14:44:07 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-10.6 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, KAM_NUMSUBJECT, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy= X-HELO: mx2.suse.de Received: from mx2.suse.de (HELO mx2.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 08 Dec 2017 14:44:06 +0000 Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id E248CABFA for ; Fri, 8 Dec 2017 14:44:03 +0000 (UTC) Date: Fri, 8 Dec 2017 15:44:03 +0100 (CET) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix PR81782 Message-ID: User-Agent: Alpine 2.20 (LSU 67 2015-01-07) MIME-Version: 1.0 The following fixes spurious uninit warnings for zero-sized arrays. Bootstrapped and tested on x86_64-unknown-linux-gnu, applied. Richard. 2017-12-08 Richard Biener PR middle-end/81782 * tree-ssa-uninit.c (warn_uninitialized_vars): Properly handle accesses outside of zero-sized vars. * gcc.dg/uninit-pr81782.c: New testcase. Index: gcc/tree-ssa-uninit.c =================================================================== --- gcc/tree-ssa-uninit.c (revision 255499) +++ gcc/tree-ssa-uninit.c (working copy) @@ -296,8 +296,8 @@ warn_uninitialized_vars (bool warn_possi variable. */ if (DECL_P (base) && ref.size != -1 - && ref.max_size == ref.size - && (ref.offset + ref.size <= 0 + && ((ref.max_size == ref.size + && ref.offset + ref.size <= 0) || (ref.offset >= 0 && DECL_SIZE (base) && TREE_CODE (DECL_SIZE (base)) == INTEGER_CST Index: gcc/testsuite/gcc.dg/uninit-pr81782.c =================================================================== --- gcc/testsuite/gcc.dg/uninit-pr81782.c (nonexistent) +++ gcc/testsuite/gcc.dg/uninit-pr81782.c (working copy) @@ -0,0 +1,14 @@ +/* { dg-do compile } */ +/* { dg-options "-Wmaybe-uninitialized" } */ + +int +foo (void) +{ + char empty_array[] = { }; + int i, ret = 0; + + for (i = 0; i < (int) (sizeof (empty_array) / sizeof (empty_array[0])); i++) + ret = empty_array[i]; /* { dg-bogus "uninitialized" } */ + + return ret; +}