From patchwork Thu Aug 19 16:59:16 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 62203 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 3B11AB70E2 for ; Fri, 20 Aug 2010 02:59:36 +1000 (EST) Received: (qmail 8154 invoked by alias); 19 Aug 2010 16:59:35 -0000 Received: (qmail 8101 invoked by uid 22791); 19 Aug 2010 16:59:33 -0000 X-SWARE-Spam-Status: No, hits=-6.0 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, 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; Thu, 19 Aug 2010 16:59:19 +0000 Received: from int-mx08.intmail.prod.int.phx2.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o7JGxIW1004642 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 19 Aug 2010 12:59:18 -0400 Received: from [IPv6:::1] (ovpn-113-45.phx2.redhat.com [10.3.113.45]) by int-mx08.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o7JGxHHp004962 for ; Thu, 19 Aug 2010 12:59:17 -0400 Message-ID: <4C6D62E4.4030207@redhat.com> Date: Thu, 19 Aug 2010 12:59:16 -0400 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.11) Gecko/20100814 Lightning/1.0b1 Shredder/3.0.7pre MIME-Version: 1.0 To: gcc-patches List Subject: C++/gimplify PATCH for c++/45307 (store of empty class not removed in gimplification) 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 The code in cp-gimplify for eliminating empty stores didn't get a chance to remove this one because gimplify_init_constructor moved it into the pre-queue. Fixed thus. Tested x86_64-pc-linux-gnu, applied to trunk. commit 6edaaca64b5498d9c3b267cb0d60d70d801b5dd5 Author: Jason Merrill Date: Tue Aug 17 14:51:04 2010 -0400 PR c++/45307 * gimplify.c (gimplify_init_constructor): Just return GS_UNHANDLED if ctor is empty. (gimplify_modify_expr_rhs): Adjust. diff --git a/gcc/cp/cp-gimplify.c b/gcc/cp/cp-gimplify.c index abd5bf3..e5a7f26 100644 --- a/gcc/cp/cp-gimplify.c +++ b/gcc/cp/cp-gimplify.c @@ -575,15 +575,18 @@ cp_gimplify_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p) TREE_OPERAND (*expr_p, 1) = build1 (VIEW_CONVERT_EXPR, TREE_TYPE (op0), op1); - else if ((is_gimple_lvalue (op1) || INDIRECT_REF_P (op1)) - && !(TREE_CODE (op1) == CALL_EXPR - && CALL_EXPR_RETURN_SLOT_OPT (op1)) + else if ((is_gimple_lvalue (op1) || INDIRECT_REF_P (op1) + || (TREE_CODE (op1) == CONSTRUCTOR + && CONSTRUCTOR_NELTS (op1) == 0) + || (TREE_CODE (op1) == CALL_EXPR + && !CALL_EXPR_RETURN_SLOT_OPT (op1))) && is_really_empty_class (TREE_TYPE (op0))) { /* Remove any copies of empty classes. We check that the RHS - has a simple form so that TARGET_EXPRs and CONSTRUCTORs get - reduced properly, and we leave the return slot optimization - alone because it isn't a copy. + has a simple form so that TARGET_EXPRs and non-empty + CONSTRUCTORs get reduced properly, and we leave the return + slot optimization alone because it isn't a copy (FIXME so it + shouldn't be represented as one). Also drop volatile variables on the RHS to avoid infinite recursion from gimplify_expr trying to load the value. */ diff --git a/gcc/gimplify.c b/gcc/gimplify.c index 8b97ee3..7e33666 100644 --- a/gcc/gimplify.c +++ b/gcc/gimplify.c @@ -4237,6 +4237,10 @@ gimplify_modify_expr_rhs (tree *expr_p, tree *from_p, tree *to_p, break; case CONSTRUCTOR: + /* If we already made some changes, let the front end have a + crack at this before we break it down. */ + if (ret != GS_UNHANDLED) + break; /* If we're initializing from a CONSTRUCTOR, break this into individual MODIFY_EXPRs. */ return gimplify_init_constructor (expr_p, pre_p, post_p, want_value, diff --git a/gcc/testsuite/g++.dg/tree-ssa/empty-2.C b/gcc/testsuite/g++.dg/tree-ssa/empty-2.C new file mode 100644 index 0000000..728678a --- /dev/null +++ b/gcc/testsuite/g++.dg/tree-ssa/empty-2.C @@ -0,0 +1,8 @@ +// PR c++/45307 +// { dg-options -fdump-tree-gimple } + +struct fallible_t { }; +const fallible_t fallible = fallible_t(); + +// { dg-final { scan-tree-dump-not "fallible" "gimple" } } +// { dg-final { cleanup-tree-dump "gimple" } }