From patchwork Thu Apr 16 15:05:04 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 461792 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 2F279140134 for ; Fri, 17 Apr 2015 01:05:36 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass reason="1024-bit key; unprotected key" header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=o7BFbuyB; dkim-adsp=none (unprotected policy); dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :date:to:cc:subject:in-reply-to:message-id:references :mime-version:content-type; q=dns; s=default; b=uGhNKiF7sYTA5v9u tAIzYLFhNdCR99MkXvyw8RFM7lwADbxyH40oQOsaXpdN8ez4ZM8CvKShzWX8vhDx sIW8DY1FeK5EfyaKPQkbG8CsMUbJHjBIxCJ/BVmpcZWrCFZA8eORC5FZzqDTmAYe kv2b6GIlMNLgRyEaFD/e/KrN0Hk= 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 :date:to:cc:subject:in-reply-to:message-id:references :mime-version:content-type; s=default; bh=ETQWXeZSgQ3R6GYaY7deso W3egM=; b=o7BFbuyBYzSQ/OUKKZtiKRu1an/G8P+kiN9KKBnoQJlg/ltA3pMvZk AHS5jjJc+ir5v5WkPTnX0DBRFwVo7pMQmi7c2aSOCqpKWb1wQAqsetWdTdWelcT9 21QDj1qJfIvQIzn+txZORrTEPGRSodsZDnSsrI9BSD5dejLUhbsm0= Received: (qmail 98155 invoked by alias); 16 Apr 2015 15:05:28 -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 98145 invoked by uid 89); 16 Apr 2015 15:05:27 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.3 required=5.0 tests=AWL, BAYES_05, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_DNSWL_LOW autolearn=no version=3.3.2 X-HELO: mail-qc0-f172.google.com Received: from mail-qc0-f172.google.com (HELO mail-qc0-f172.google.com) (209.85.216.172) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Thu, 16 Apr 2015 15:05:24 +0000 Received: by qcyk17 with SMTP id k17so7793020qcy.1 for ; Thu, 16 Apr 2015 08:05:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:date:to:cc:subject:in-reply-to:message-id :references:user-agent:mime-version:content-type; bh=vJYsl4BiP8yzrc203vUnf/sK+GPnpmjdP9uJYUT9QQo=; b=ZmOO9Trin8kJbPGZ97jjnLVHr7xXi9rEXhxJSVxdzY+czLYoVBJu3UybgxNvYFxCmZ cWfQRTZILrY52OUE4I9+lVruYSgk35tbv6rwYXBxfJuvygY2Yw41WKWuT2M3gI8P95Cv VagsvyS0VrHCrsWRl4suUYzX39JXsm/9MzAXdGmVMOmszHMzBefbwn59nY+/FXtPLmmb W0/fOzXnG3b35EAPulo+DKl207BSdMJ5adg64RvJs1sa4hUNNT5sj0toKOEVZYYnqLm6 hyS6Mae/LEg0xVo6mW+pYBl/TwZErCKJgNK4ETwM+kn/tfeLtLR6Zt0fqbHPrpDcThTC FGuw== X-Gm-Message-State: ALoCoQmvSx5VEU97cc6S4Ou/0ShSih5oM1E4GlI0BpI0k+f/WUATPcyHdNcjt/Zp5r5/mdevqAbC X-Received: by 10.140.151.15 with SMTP id 15mr38798976qhx.104.1429196722714; Thu, 16 Apr 2015 08:05:22 -0700 (PDT) Received: from [192.168.1.130] (ool-4353acd8.dyn.optonline.net. [67.83.172.216]) by mx.google.com with ESMTPSA id j190sm5755440qhc.33.2015.04.16.08.05.21 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 16 Apr 2015 08:05:21 -0700 (PDT) From: Patrick Palka X-Google-Original-From: Patrick Palka Date: Thu, 16 Apr 2015 11:05:04 -0400 (EDT) To: Jason Merrill cc: Patrick Palka , gcc-patches@gcc.gnu.org Subject: Re: [PATCH] Do not discard the constructors of empty structs [PR c++/64527] In-Reply-To: <552FC7F2.7010707@redhat.com> Message-ID: References: <1429146015-25249-1-git-send-email-patrick@parcs.ath.cx> <552FC7F2.7010707@redhat.com> User-Agent: Alpine 2.11 (DEB 23 2013-08-11) MIME-Version: 1.0 On Thu, 16 Apr 2015, Jason Merrill wrote: > On 04/15/2015 09:00 PM, Patrick Palka wrote: >> - if (!cleared || num_nonzero_elements > 0) > > How about adding || TREE_SIDE_EFFECTS (TREE_OPERAND (*expr_p), 1) to this > test rather than removing it entirely? That works too. Does the following patch look OK if testing succeeds? gcc/ PR c++/64527 * gcc/gimplify.c (gimplify_init_constructor): Always emit a side-effecting constructor. gcc/testsuite/ * g++.dg/init/pr64527.C: New test. --- gcc/gimplify.c | 11 ++++++++--- gcc/testsuite/g++.dg/init/pr64527.C | 21 +++++++++++++++++++++ 2 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/g++.dg/init/pr64527.C diff --git a/gcc/gimplify.c b/gcc/gimplify.c index ff0a225..29d3f4d 100644 --- a/gcc/gimplify.c +++ b/gcc/gimplify.c @@ -3994,6 +3994,9 @@ gimplify_init_constructor (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p, pre_p, post_p, &preeval_data); } + bool ctor_has_side_effects_p + = TREE_SIDE_EFFECTS (TREE_OPERAND (*expr_p, 1)); + if (cleared) { /* Zap the CONSTRUCTOR element list, which simplifies this case. @@ -4006,9 +4009,11 @@ gimplify_init_constructor (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p, } /* If we have not block cleared the object, or if there are nonzero - elements in the constructor, add assignments to the individual - scalar fields of the object. */ - if (!cleared || num_nonzero_elements > 0) + elements in the constructor, or if the constructor has side effects, + add assignments to the individual scalar fields of the object. */ + if (!cleared + || num_nonzero_elements > 0 + || ctor_has_side_effects_p) gimplify_init_ctor_eval (object, elts, pre_p, cleared); *expr_p = NULL_TREE; diff --git a/gcc/testsuite/g++.dg/init/pr64527.C b/gcc/testsuite/g++.dg/init/pr64527.C new file mode 100644 index 0000000..36b8214 --- /dev/null +++ b/gcc/testsuite/g++.dg/init/pr64527.C @@ -0,0 +1,21 @@ +// { dg-do run { target c++11 } } + +static int g; + +struct A { + A() { g = 1; } +}; + +struct accessor { + A a; + int x; +}; + +int +main (void) +{ + (void) accessor{}; + + if (g != 1) + __builtin_abort (); +}