From patchwork Fri Apr 20 19:20:52 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 154119 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]) by ozlabs.org (Postfix) with SMTP id 31EE6B6FBC for ; Sat, 21 Apr 2012 05:21:26 +1000 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1335554487; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Received:Date:From:To:Cc:Subject:Message-ID:Reply-To: MIME-Version:Content-Type:Content-Disposition:User-Agent: Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:Sender:Delivered-To; bh=GuPS/vJnGylZRfYr1+AG +0Uq9dk=; b=D8IQnWKvDrTpevYxCOVfg7XvAMKnNo4iuKFp6EkeGz4I+fJBNBG0 vfE5e2mFsHOvXZkSo/TqywOa1ZUMUq1qWfWo17UOlkt+SYx5OPn90ktZV34jcl5S 244tja3G9e+Au8tcxH2WH0oVN4tug3pxoaVhnMkmJvRdK4gwERUeI2Q= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Received:Received:Date:From:To:Cc:Subject:Message-ID:Reply-To:MIME-Version:Content-Type:Content-Disposition:User-Agent:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=flKmpIV1O9+aD+Y8N57w6D6xpHgG3J5vIkRZFiLaCXC7em+dNxXKkLj/mM0hlA NbggOgVwVq7nemhcLVT20AmTGjf5K9afyzaBkFYbhW7EuX17eC2wlXmn/sjPr3dj 6us408uwEcWLHHDGm0GcyeskSkyhIA0JoJ6erUx6TlFCk=; Received: (qmail 17774 invoked by alias); 20 Apr 2012 19:21:21 -0000 Received: (qmail 17764 invoked by uid 22791); 20 Apr 2012 19:21:19 -0000 X-SWARE-Spam-Status: No, hits=-6.3 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, RCVD_IN_DNSWL_HI, RCVD_IN_HOSTKARMA_W, SPF_HELO_PASS, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 20 Apr 2012 19:21:01 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q3KJKvQE010807 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 20 Apr 2012 15:20:57 -0400 Received: from tyan-ft48-01.lab.bos.redhat.com (tyan-ft48-01.lab.bos.redhat.com [10.16.42.4]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q3KJKtHg009643 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 20 Apr 2012 15:20:56 -0400 Received: from tyan-ft48-01.lab.bos.redhat.com (tyan-ft48-01.lab.bos.redhat.com [127.0.0.1]) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4) with ESMTP id q3KJKr4x027657; Fri, 20 Apr 2012 21:20:54 +0200 Received: (from jakub@localhost) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4/Submit) id q3KJKqxV027655; Fri, 20 Apr 2012 21:20:52 +0200 Date: Fri, 20 Apr 2012 21:20:52 +0200 From: Jakub Jelinek To: "Joseph S. Myers" Cc: gcc-patches@gcc.gnu.org Subject: [C PATCH] Fix -Woverride-init (PR c/52880) Message-ID: <20120420192052.GE16117@tyan-ft48-01.lab.bos.redhat.com> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes 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 Hi! This patch fixes -Woverride-init. IMHO we don't want to ever warn from within set_nonincremental_init, which moves over values from the constructor_elements vector to constructor_pending_elts AVL. The reason for that is that when switching from the non-incremental mode where values only live in the AVL tree to incremental, we don't remove values from the AVL tree, just copy them to the vector. So, if we go from non-incremental to incremental and back to non-incremental, we warn on all the values that are "added" to the AVL tree while already there, unless we call add_pending_init with IMPLICIT = true as done in this patch. When we actually want to warn, IMHO we are always in the non-incremental mode, because if we are in incremental mode, we switch to non-incremental mode first if not writing to the next unfilled field, and the next unfilled field can't be present in the AVL, otherwise it would be filled already. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk/4.7? 2012-04-19 Jakub Jelinek PR c/52880 * c-typeck.c (set_nonincremental_init, set_nonincremental_init_from_string): Pass true instead of false as IMPLICIT to add_pending_init. * gcc.dg/pr52880.c: New test. Jakub --- gcc/c-typeck.c.jj 2012-04-19 11:09:13.000000000 +0200 +++ gcc/c-typeck.c 2012-04-19 13:21:15.642080390 +0200 @@ -7597,7 +7597,7 @@ set_nonincremental_init (struct obstack FOR_EACH_CONSTRUCTOR_ELT (constructor_elements, ix, index, value) { - add_pending_init (index, value, NULL_TREE, false, + add_pending_init (index, value, NULL_TREE, true, braced_init_obstack); } constructor_elements = 0; @@ -7690,7 +7690,7 @@ set_nonincremental_init_from_string (tre } value = build_int_cst_wide (type, val[1], val[0]); - add_pending_init (purpose, value, NULL_TREE, false, + add_pending_init (purpose, value, NULL_TREE, true, braced_init_obstack); } --- gcc/testsuite/gcc.dg/pr52880.c.jj 2012-04-19 14:55:14.942948973 +0200 +++ gcc/testsuite/gcc.dg/pr52880.c 2012-04-19 14:54:55.000000000 +0200 @@ -0,0 +1,10 @@ +/* PR c/52880 */ +/* { dg-do compile } */ +/* { dg-options "-Woverride-init" } */ + +struct A { int a; int b; }; +struct B { struct A c; int d, e; }; +struct B f = { .c.a = 0, .e = 1, .d = 2, .c.b = 3 }; +struct C { int g; int h; }; +struct D { int i; struct C j; int k; }; +struct D l = { .j.g = 0, .k = 1, .i = 2, .j.h = 3 };