From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17456 invoked by alias); 27 Nov 2014 06:29:27 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 17445 invoked by uid 89); 27 Nov 2014 06:29:26 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.9 required=5.0 tests=AWL,BAYES_00,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: smtp.mozilla.org Received: from mx1.corp.phx1.mozilla.com (HELO smtp.mozilla.org) (63.245.216.69) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Thu, 27 Nov 2014 06:29:24 +0000 Received: from iceball.home (pool-71-188-77-215.cmdnnj.fios.verizon.net [71.188.77.215]) (Authenticated sender: tsaunders@mozilla.com) by mx1.mail.corp.phx1.mozilla.com (Postfix) with ESMTPSA id 7BCF0F2290; Wed, 26 Nov 2014 22:29:22 -0800 (PST) From: tsaunders@mozilla.com To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, Trevor Saunders Subject: [PATCH 1/2] [C++] Remove tree_list from warn_hidden Date: Thu, 27 Nov 2014 08:53:00 -0000 Message-Id: <1417069734-23041-1-git-send-email-tsaunders@mozilla.com> X-IsSubscribed: yes X-SW-Source: 2014-11/txt/msg03364.txt.bz2 From: Trevor Saunders Hi, I'll claim this is kind of a bug fix in so much as excessive gc allocation and use of tree_list is a bug. bootstrapped + regtested x86_64-unknown-linux-gnu, ok? Trev cp/ * class.c (warn_hidden): Use auto_vec instead of tree_list to hold base_fndecls. (get_basefndecls): Adjust. diff --git a/gcc/cp/class.c b/gcc/cp/class.c index c83c8ad..16279df 100644 --- a/gcc/cp/class.c +++ b/gcc/cp/class.c @@ -129,7 +129,7 @@ vec *local_classes; static tree get_vfield_name (tree); static void finish_struct_anon (tree); static tree get_vtable_name (tree); -static tree get_basefndecls (tree, tree); +static void get_basefndecls (tree, tree, vec *); static int build_primary_vtable (tree, tree); static int build_secondary_vtable (tree); static void finish_vtbls (tree); @@ -2717,16 +2717,16 @@ modify_all_vtables (tree t, tree virtuals) /* Get the base virtual function declarations in T that have the indicated NAME. */ -static tree -get_basefndecls (tree name, tree t) +static void +get_basefndecls (tree name, tree t, vec *base_fndecls) { tree methods; - tree base_fndecls = NULL_TREE; int n_baseclasses = BINFO_N_BASE_BINFOS (TYPE_BINFO (t)); int i; /* Find virtual functions in T with the indicated NAME. */ i = lookup_fnfields_1 (t, name); + bool found_decls = false; if (i != -1) for (methods = (*CLASSTYPE_METHOD_VEC (t))[i]; methods; @@ -2736,20 +2736,20 @@ get_basefndecls (tree name, tree t) if (TREE_CODE (method) == FUNCTION_DECL && DECL_VINDEX (method)) - base_fndecls = tree_cons (NULL_TREE, method, base_fndecls); + { + base_fndecls->safe_push (method); + found_decls = true; + } } - if (base_fndecls) - return base_fndecls; + if (found_decls) + return; for (i = 0; i < n_baseclasses; i++) { tree basetype = BINFO_TYPE (BINFO_BASE_BINFO (TYPE_BINFO (t), i)); - base_fndecls = chainon (get_basefndecls (name, basetype), - base_fndecls); + get_basefndecls (name, basetype, base_fndecls); } - - return base_fndecls; } /* If this declaration supersedes the declaration of @@ -2811,7 +2811,6 @@ warn_hidden (tree t) tree fn; tree name; tree fndecl; - tree base_fndecls; tree base_binfo; tree binfo; int j; @@ -2820,19 +2819,18 @@ warn_hidden (tree t) have the same name. Figure out what name that is. */ name = DECL_NAME (OVL_CURRENT (fns)); /* There are no possibly hidden functions yet. */ - base_fndecls = NULL_TREE; + auto_vec base_fndecls; /* Iterate through all of the base classes looking for possibly hidden functions. */ for (binfo = TYPE_BINFO (t), j = 0; BINFO_BASE_ITERATE (binfo, j, base_binfo); j++) { tree basetype = BINFO_TYPE (base_binfo); - base_fndecls = chainon (get_basefndecls (name, basetype), - base_fndecls); + get_basefndecls (name, basetype, &base_fndecls); } /* If there are no functions to hide, continue. */ - if (!base_fndecls) + if (!base_fndecls.exists ()) continue; /* Remove any overridden functions. */ @@ -2842,28 +2840,27 @@ warn_hidden (tree t) if (TREE_CODE (fndecl) == FUNCTION_DECL && DECL_VINDEX (fndecl)) { - tree *prev = &base_fndecls; - - while (*prev) /* If the method from the base class has the same signature as the method from the derived class, it has been overridden. */ - if (same_signature_p (fndecl, TREE_VALUE (*prev))) - *prev = TREE_CHAIN (*prev); - else - prev = &TREE_CHAIN (*prev); + for (size_t k = 0; k < base_fndecls.length (); k++) + if (base_fndecls[k] + && same_signature_p (fndecl, base_fndecls[k])) + base_fndecls[k] = NULL_TREE; } } /* Now give a warning for all base functions without overriders, as they are hidden. */ - while (base_fndecls) - { - /* Here we know it is a hider, and no overrider exists. */ - warning (OPT_Woverloaded_virtual, "%q+D was hidden", TREE_VALUE (base_fndecls)); - warning (OPT_Woverloaded_virtual, " by %q+D", fns); - base_fndecls = TREE_CHAIN (base_fndecls); - } + size_t k; + tree base_fndecl; + FOR_EACH_VEC_ELT (base_fndecls, k, base_fndecl) + if (base_fndecl) + { + /* Here we know it is a hider, and no overrider exists. */ + warning (OPT_Woverloaded_virtual, "%q+D was hidden", base_fndecl); + warning (OPT_Woverloaded_virtual, " by %q+D", fns); + } } } -- 2.1.3