From patchwork Fri Jan 17 13:37:50 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Polacek X-Patchwork-Id: 312067 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.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 857862C007A for ; Sat, 18 Jan 2014 00:38:03 +1100 (EST) 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:cc:subject:message-id:mime-version:content-type; q=dns; s=default; b=Rob/B8DiK68YpH4xBDeT9G/2xbOj+wwE91BqdtwlnB8gNrdxo1 Bm25GdtbOVx91+uOQDY3l1QIaUTK7vEiTVZMEMv2TWgt3ZMADLabMVqKaDVLAdNH it1pHTJDJx6n5oPxXbAWG79oEg209vifK5YAUQBMMAbAiPLHjPPXD/r58= 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:cc:subject:message-id:mime-version:content-type; s= default; bh=4sk4phepAxW/1qnsFLq/UrMwgcg=; b=qdE7I4a7sFN3f+snevZj V5VGoqL3yFD8xx4AXlm7EAkrcB79CsJ4kHz5d+jCDG8IvmtU83vtswogW1UDqsbj IzKCHsl2kOuE9QqvmZVq9qHb491C1yiWroopdVoOp4uJMof16Ad6AXTwqn8HxDNM 8kISR9z1uApL2IxKGR3DRoQ= Received: (qmail 30398 invoked by alias); 17 Jan 2014 13:37:57 -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 30388 invoked by uid 89); 17 Jan 2014 13:37:56 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.1 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 17 Jan 2014 13:37:56 +0000 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s0HDbs8B000866 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 17 Jan 2014 08:37:55 -0500 Received: from redhat.com (ovpn-116-106.ams2.redhat.com [10.36.116.106]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s0HDbp7A013905 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Fri, 17 Jan 2014 08:37:53 -0500 Date: Fri, 17 Jan 2014 14:37:50 +0100 From: Marek Polacek To: GCC Patches Cc: Richard Biener Subject: [PATCH] Don't fold zero-sized elements (PR c/58346) Message-ID: <20140117133750.GI8907@redhat.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) This is the real fix for PR58346. I'd say the easiest solution is just not fold the zero-sized elements. Bootstrapped/regtested on x86_64-linux, ok for trunk? 2014-01-17 Marek Polacek PR c/58346 * gimple-fold.c (fold_array_ctor_reference): Don't fold if element size is zero. testsuite/ * gcc.dg/pr58346.c: New test. Marek --- gcc/gimple-fold.c.mp2 2014-01-17 12:03:56.149446880 +0100 +++ gcc/gimple-fold.c 2014-01-17 12:04:00.450462677 +0100 @@ -2940,7 +2940,8 @@ fold_array_ctor_reference (tree type, tr be larger than size of array element. */ if (!TYPE_SIZE_UNIT (type) || TREE_CODE (TYPE_SIZE_UNIT (type)) != INTEGER_CST - || elt_size.slt (tree_to_double_int (TYPE_SIZE_UNIT (type)))) + || elt_size.slt (tree_to_double_int (TYPE_SIZE_UNIT (type))) + || elt_size.is_zero ()) return NULL_TREE; /* Compute the array index we look for. */ --- gcc/testsuite/gcc.dg/pr58346.c.mp2 2014-01-17 12:27:26.180127058 +0100 +++ gcc/testsuite/gcc.dg/pr58346.c 2014-01-17 12:28:20.466332046 +0100 @@ -0,0 +1,19 @@ +/* PR tree-optimization/58346 */ +/* { dg-do compile } */ +/* { dg-options "-O" } */ + +struct U {}; +static struct U b[1] = { }; +extern void bar (struct U); + +void +foo (void) +{ + bar (b[0]); +} + +void +baz (void) +{ + foo (); +}