From patchwork Tue Sep 20 19:32:14 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 115626 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 3D920B6F92 for ; Wed, 21 Sep 2011 05:32:39 +1000 (EST) Received: (qmail 4960 invoked by alias); 20 Sep 2011 19:32:36 -0000 Received: (qmail 4944 invoked by uid 22791); 20 Sep 2011 19:32:34 -0000 X-SWARE-Spam-Status: No, hits=-6.7 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, SPF_HELO_PASS 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; Tue, 20 Sep 2011 19:32:18 +0000 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p8KJWIKh025631 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 20 Sep 2011 15:32:18 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p8KJWHww029491 for ; Tue, 20 Sep 2011 15:32:17 -0400 Received: from [0.0.0.0] (ovpn-113-145.phx2.redhat.com [10.3.113.145]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id p8KJWFrd018872 for ; Tue, 20 Sep 2011 15:32:16 -0400 Message-ID: <4E78EA3E.1080201@redhat.com> Date: Tue, 20 Sep 2011 15:32:14 -0400 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; Linux i686; rv:6.0.2) Gecko/20110906 Thunderbird/6.0.2 MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH to avoid double copying of default arguments 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 While working on something else I noticed that we were copying the trees in a default argument twice: once in break_out_target_exprs and then again with an explicit unshare_expr. So I removed the redundant unshare_expr. This didn't cause any regressions by itself, but just to be safe I also changed bot_manip to copy everything. Tested x86_64-pc-linux-gnu, applying to trunk. commit 53528dc80860cd96862c008501f3ad419bcaa7d5 Author: Jason Merrill Date: Thu Sep 15 15:13:33 2011 -0400 * call.c (convert_default_arg): Avoid redundant copy. * tree.c (bot_manip): Copy everything. diff --git a/gcc/cp/call.c b/gcc/cp/call.c index 873b48b..b616cff 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -6130,6 +6130,8 @@ convert_default_arg (tree type, tree arg, tree fn, int parmnum) we must not perform access checks here. */ push_deferring_access_checks (dk_no_check); + /* We must make a copy of ARG, in case subsequent processing + alters any part of it. */ arg = break_out_target_exprs (arg); if (TREE_CODE (arg) == CONSTRUCTOR) { @@ -6140,14 +6142,6 @@ convert_default_arg (tree type, tree arg, tree fn, int parmnum) } else { - /* We must make a copy of ARG, in case subsequent processing - alters any part of it. For example, during gimplification a - cast of the form (T) &X::f (where "f" is a member function) - will lead to replacing the PTRMEM_CST for &X::f with a - VAR_DECL. We can avoid the copy for constants, since they - are never modified in place. */ - if (!CONSTANT_CLASS_P (arg)) - arg = unshare_expr (arg); arg = convert_for_initialization (0, type, arg, LOOKUP_IMPLICIT, ICR_DEFAULT_ARGUMENT, fn, parmnum, tf_warning_or_error); diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c index 9987953..a9e1a26 100644 --- a/gcc/cp/tree.c +++ b/gcc/cp/tree.c @@ -1865,9 +1865,13 @@ bot_manip (tree* tp, int* walk_subtrees, void* data) if (!TYPE_P (t) && TREE_CONSTANT (t) && !TREE_SIDE_EFFECTS (t)) { - /* There can't be any TARGET_EXPRs or their slot variables below - this point. */ + /* There can't be any TARGET_EXPRs or their slot variables below this + point. But we must make a copy, in case subsequent processing + alters any part of it. For example, during gimplification a cast + of the form (T) &X::f (where "f" is a member function) will lead + to replacing the PTRMEM_CST for &X::f with a VAR_DECL. */ *walk_subtrees = 0; + *tp = unshare_expr (t); return NULL_TREE; } if (TREE_CODE (t) == TARGET_EXPR) @@ -1928,8 +1932,8 @@ bot_replace (tree* t, /* When we parse a default argument expression, we may create temporary variables via TARGET_EXPRs. When we actually use the - default-argument expression, we make a copy of the expression, but - we must replace the temporaries with appropriate local versions. */ + default-argument expression, we make a copy of the expression + and replace the temporaries with appropriate local versions. */ tree break_out_target_exprs (tree t)